#!/usr/bin/env python3 import urllib.request,itertools exec(urllib.request.urlopen('https://eval.dan.co.jp/friends/2026/10/31/c0ff0ef5348609407d7df832dff85896f864a9cfc694b5feed038db12423e4e6').read()) def gen(i,b): if i==7: st=[0]*7 for bl in b: m=min(bl) for x in bl:st[x]=m yield tuple(st) else: for j in range(len(b)): b[j].append(i) yield from gen(i-(-1),b) b[j].pop() b.append([i]) yield from gen(i-(-1),b) b.pop() def direct(st): A=set() for u,v in S0: for v2,w in T0: if st[v]==st[v2] and st[u]!=st[w] and st[v]!=st[w]:A.add((st[u],st[v],st[w])) return A def check(st): SL=list({(st[u],st[v]) for u,v in S0}) TL=list({(st[u],st[v]) for u,v in T0}) for tags in itertools.product([0,1],repeat=len(SL)): ok=True for i in range(len(SL)): r,s=SL[i] for u,t in TL: if u==s: if tags[i]==0 and r!=t:ok=False if tags[i]==1 and s!=t:ok=False if ok:return True return False allterm=[st for st in gen(0,[]) if not direct(st)] print('terminal count',len(allterm)) for st in sorted(allterm): print(''.join('abcdefg'[i] for i in st),'classes',len(set(st)),'real',check(st))