from fractions import Fraction as Q def run(load,check): E=Q(25,23);P=Q(70,69);J=Q(300,299);reg=load('C286_DATA.json')['target_register'];coords={r['center'] for r in reg};rows=[] def ids(x):return[i for i,r in enumerate(reg) if r['center']==x] def f(n,x):return n+E*(x-n) for k,hit in enumerate(load('C379_DATA.json')['qualified_regular_hits']): A,B,x,y,N=hit['coordinate_tuple'];h=y-x;z=f(N,x);w=f(N+h,y);Ap=z-h/(J-1);Bp=z-h/(P-1) check('source equal gain '+str(k),h==2 and B-A==460 and N-x==460 and z==x-40 and w==z+2) check('unique transported pivots '+str(k),Ap==A-40 and Bp==B-40 and Ap==f(N,A)+52 and Bp==f(N,B)+12) check('J pivot sourced, P pivot absent '+str(k),len(ids(Ap))==2 and all(reg[j]['role']=='Shem death' and reg[j]['tradition'] in ['SP','LXX'] for j in ids(Ap)) and not ids(Bp)) check('both Shem endpoints admitted '+str(k),bool(ids(z)) and bool(ids(w))) lifts=[] for tradition,rail in [('SP','primary'),('LXX',None)]: ns=[r for r in reg if r['center']==N and r['role']=='Noah birth' and r['tradition']==tradition and r.get('rail')==rail and r['Cainan']==0 and r['Terah60']==0] check('one context Noah '+str((k,tradition)),len(ns)==1);nr=ns[0] def select(role,gear,center):return[r for r in reg if r['tradition']==tradition and r['role']==role and r['gear']==gear and r.get('rail')==rail and r['Cainan']==0 and r['Terah60']==0 and r['full430']==nr['full430'] and r['center']==center] one=select('Shem birth',nr['gear'],z);two=select('Shem birth',nr['gear']+1,w);nextn=select('Noah birth',nr['gear']+1,N+h) check('typed moving E source lift '+str((k,tradition)),len(one)==len(two)==len(nextn)==1) lifts.append({'tradition':tradition,'Noah_input_record':nr,'Noah_next_record':nextn[0],'Shem_input_record':one[0],'Shem_output_record':two[0]}) rows.append({'original_tuple':[A,B,x,y,N],'E_image_input':str(z),'E_image_output_with_next_Noah':str(w),'required_J_pivot':str(Ap),'required_P_pivot':str(Bp),'static_E_J_pivot':str(f(N,A)),'static_E_P_pivot':str(f(N,B)),'required_J_pivot_record_indices':ids(Ap),'required_P_pivot_record_indices':ids(Bp),'Shem_input_record_indices':ids(z),'Shem_output_record_indices':ids(w),'source_context_lifts':lifts}) check('finite counts',len(rows)==4 and sum(len(r['source_context_lifts']) for r in rows)==8) return {'step':'C385','rows':rows,'counts':{'original_common_repairs':4,'Shem_coordinate_edges':4,'SP_LXX_context_lifts':8,'required_pivot_slots':8,'admitted_required_pivot_slots':4,'source_closed_E_J_transported_squares':4,'source_closed_E_P_transported_squares':0},'unique_pivot_formula':'For an existing image edge z -> z+h, J pivot=z-299h and P pivot=z-69h. With z=x-40 and h2, both original pivots must move by-40.','interpretation':'The moving E comparison carries the admitted MT Noah edge to existing SP/LXX Shem edges. J carries the image edge with an existing next-Gear SP/LXX Shem-death pivot. P fails source closure because its uniquely required pivot is absent even when all Noah/Shem/Flood roles are allowed. The J pivot changes event role from MT Flood to SP/LXX Shem death.'}