# Independent check of iis:2611.00134 (Monopoly vs backgammon displacement multisets).
# Rules per Clifton-Harris-Khaqan arXiv:2611.29890 Sec 1: spots 1..n; on collision
#  Monopoly: arriving car goes to first vacant spot from the start of the street.
#  Backgammon: arriving car takes its spot; bumped car goes to first vacant spot from start.
# Displacement multiset: |final spot - preference| over cars not in their preferred spot.
import itertools, sys
from collections import Counter
def sim(a, n, mode):
    spot = [None]*(n+1); where = [0]*len(a)
    for i, p in enumerate(a):
        if spot[p] is None: spot[p] = i; where[i] = p; continue
        e = spot.index(None, 1)
        if mode == 'M': spot[e] = i; where[i] = e
        else:
            j = spot[p]; spot[p] = i; where[i] = p; spot[e] = j; where[j] = e
    return Counter(abs(where[i]-a[i]) for i in range(len(a)) if where[i] != a[i])
def crit(a, n):  # claimed criterion: each first request finds its spot vacant
    occ = set(); seen = set()
    for p in a:
        if p not in seen:
            if p in occ: return False
            seen.add(p); occ.add(p)
        else:
            occ.add(min(s for s in range(1, n+1) if s not in occ))
    return True
def rec(n):
    a = [1]+[0]*n
    for t in range(n):
        b = [0]*(n+1)
        for d in range(n+1):
            b[d] = d*a[d] + ((n-t)*a[d-1] if d else 0)
        a = b
    return a
assert sim((1,4,4,3,2,2),6,'M') == Counter([2,3,4]); assert sim((1,4,4,3,2,2),6,'B') == Counter([1,4])
N = int(sys.argv[1])
for n in range(1, N+1):
    tot = 0; byd = Counter(); bad = 0
    for a in itertools.product(range(1, n+1), repeat=n):
        eq = sim(a, n, 'M') == sim(a, n, 'B')
        if eq != crit(a, n): bad += 1
        if eq: tot += 1; byd[len(set(a))] += 1
    r = rec(n)
    print(n, tot, sum(r), dict(sorted(byd.items())), r[1:], 'criterion mismatches:', bad, flush=True)
print('(2,2,1):', sim((2,2,1),3,'M'), sim((2,2,1),3,'B'))
