from fractions import Fraction as Q def run(load,check): J=Q(300,299);P=Q(70,69);cum=load('C365_DATA.json')['cumulative_register'];reg=load('C286_DATA.json')['target_register'];cc=[];rr=[] def cm(role,c,k):return next(r for r in cum if r['role']==role and r['Cainan']==c and r['annual_index']==k) for old in load('C364_DATA.json')['rows']: i=old['i'];u=old['P_OFF'];q=old['q_OFF'];f=cm('Flood',1,i);v=cm('Shem',0,i);x=u['coordinate'];y=v['coordinate'];a=q['coordinate'];p=f['coordinate'];yj=a+J*(x-a);yp=p+P*(x-p) check('cumulative input source gaps '+str(i),a-p==460 and a-x==598 and p-x==138) check('same sourced cumulative output '+str(i),yj==yp==y and a-y==600 and p-y==140 and y==x-2) if i in [2,3,4,5]: prior=next(r for r in load('C351_DATA.json')['rows'] if r['i']==i);check('existing C351 repair '+str(i),v==prior['P_repaired_OFF'] and v['coordinate']-old['S_ON']['coordinate']==458) cc.append({'i':i,'input_OFF_Shem':u,'J_pivot_OFF_Flood':q,'P_pivot_ON_Flood':f,'output_OFF_Shem':v,'J_input_output_gaps':[598,600],'P_input_output_gaps':[138,140],'J_image':str(yj),'P_image':str(yp),'full_C287':i in [2,3,4,5]}) for old in load('C287_DATA.json')['rows']: if not old['complete']:continue i=old['i'];N=next(r for r in old['Noah_records'] if r['tradition']=='SP');g=N['gear'];e=int(N['rail']=='companion') M=next(r for r in reg if r['tradition']=='MT' and r['role']=='Noah birth' and r['gear']==g and r['Cainan']==r['Terah60']==r['full430']==1) A=next(r for r in reg if r['tradition']=='MT' and r['role'].startswith('Flood') and r['center']==old['R'] and r['Cainan']==r['Terah60']==r['full430']==1) B=next(r for r in reg if r['tradition']=='SP' and r['role']==A['role'] and r['gear']==A['gear'] and r['Cainan']==r['Terah60']==0 and r['full430']==1) target=next(r for r in reg if r['tradition']=='MT' and r['role']=='Noah birth' and r['gear']==g+1 and r['Cainan']==r['Terah60']==r['full430']==1) x=M['center'];a=A['center'];p=B['center'];yj=a+J*(x-a);yp=p+P*(x-p) check('regular paired pivots '+str(i),p-a==460 and x-a==598+e and x-p==138+e) check('regular source agreement condition '+str(i),(yj==yp==target['center'])==(e==0) and yp-yj==Q(10,897)*e) check('regular exact residuals '+str(i),yj-target['center']==Q(e,299) and yp-target['center']==Q(e,69)) if not e:check('same fixed2K output '+str(i),N['center']-target['center']==458 and target['center']-a==600 and N['center']-a==1058) rr.append({'i':i,'rail':N['rail'],'SP_Noah':N,'input_MT_Noah':M,'J_pivot_MT_Flood':A,'P_pivot_SP_Flood':B,'candidate_next_Gear_MT_Noah':target,'J_input_gap':x-a,'P_input_gap':x-p,'J_image':str(yj),'P_image':str(yp),'common_source_output':e==0,'J_error_from_source':str(yj-target['center']),'P_error_from_source':str(yp-target['center'])}) check('two-sided primary support',[r['i'] for r in rr if r['common_source_output']]==[3,5]) return {'step':'C370','cumulative_rows':cc,'regular_rows':rr,'counts':{'cumulative_source_repairs':6,'within_complete_C287':4,'regular_common_source_repairs':2,'regular_companion_failures':2},'identity':'598→600 under300/299 and138→140 under70/69 share the same2-year gain at source Flood pivots460 apart.','source_status':'P is inherited from File46; its paired application here is a tested comparison, not a reviewed instruction prescribing the coupling. File02 gap conversion remains outside Residue Protocol.','new_source_nodes':False,'outer_preserving_repair':'Same actual endpoints as C351/C353458+600 repairs; original2K and17K outer endpoints remain fixed.'}