from fractions import Fraction as Q from itertools import product def run(load,check): K=529;d=load('C370_DATA.json');rows=[] for rr in d['regular_rows']: if not rr['common_source_output']:continue i=rr['i'];cc=next(x for x in d['cumulative_rows'] if x['i']==i);old=next(x for x in load('C364_DATA.json')['rows'] if x['i']==i) S=old['S_ON']['coordinate'];q=cc['J_pivot_OFF_Flood']['coordinate'];u=cc['input_OFF_Shem']['coordinate'];v=cc['output_OFF_Shem']['coordinate'];R=rr['J_pivot_MT_Flood']['center'];N=rr['SP_Noah']['center'];m=rr['input_MT_Noah']['center'];n=rr['candidate_next_Gear_MT_Noah']['center'] left=[S,u,q];right=[R,m,N];left2=[S,v,q];right2=[R,n,N] before=[[b-a for b in right] for a in left];after=[[b-a for b in right2] for a in left2];delta=[[after[a][b]-before[a][b] for b in range(3)] for a in range(3)] check('source two-year displacements '+str(i),v==u-2 and n==m+2) check('outer529 rectangle unchanged '+str(i),q-S==N-R==2*K and R-S==N-q==17*K and N-S==19*K and R-q==15*K) check('full cross matrix before '+str(i),before==[[17*K,18*K+69,19*K],[16*K+69,17*K+138,18*K+69],[15*K,16*K+69,17*K]]) check('full cross matrix delta '+str(i),delta==[[0,2,0],[2,4,2],[0,2,0]]) check('local repaired partitions '+str(i),[v-S,q-v]==[N-n,n-R]==[458,600]) check('central cross span is not P remainder expansion '+str(i),m-u==17*K+138 and n-v==17*K+142 and Q(70,69)*138==140 and n-v!=17*K+140) C=S+N check('source endpoint exchange survives '+str(i),C==q+R==u+m==v+n and [C-x for x in left2]==list(reversed(right2))) check('finite reversal involution '+str(i),all(C-(C-x)==x for x in left+right+left2+right2)) check('one affine map cannot fix ends and move middle '+str(i),S!=q and R!=N and v!=u and n!=m) for off in [-Q(1,4),Q(1,4)]: phase_before=[[(b+off)-(a+off) for b in right] for a in left];phase_after=[[(b+off)-(a+off) for b in right2] for a in left2] check('same-offset cross spans '+str((i,off)),phase_before==before and phase_after==after) rows.append({'i':i,'source_records':{'S_native_Shem':old['S_ON'],'q_OFF_Flood':cc['J_pivot_OFF_Flood'],'u_OFF_Shem_before':cc['input_OFF_Shem'],'v_OFF_Shem_after':cc['output_OFF_Shem'],'R_MT_Flood':rr['J_pivot_MT_Flood'],'N_SP_Noah':rr['SP_Noah'],'m_MT_Noah_before':rr['input_MT_Noah'],'n_MT_Noah_after':rr['candidate_next_Gear_MT_Noah']},'left_before':left,'left_after':left2,'right_before':right,'right_after':right2,'cross_span_before':before,'cross_span_after':after,'cross_span_delta':delta,'endpoint_exchange_sum_diagnostic':C,'sum_is_not_new_adopted_axis':True,'diagnostic_piecewise_segment_ratios':['229/230','300/299'],'source_support':'The same sourced records as C370; all four outer endpoints remain fixed.'}) check('two primary source realizations',[x['i'] for x in rows]==[3,5]) return {'step':'C374','rows':rows,'cross_span_delta':[[0,2,0],[2,4,2],[0,2,0]],'counts':{'primary_rectangles':2,'cross_spans_per_rectangle':9,'unchanged_cross_spans_per_rectangle':4,'changed_cross_spans_per_rectangle':5},'main_result':'The paired repairs preserve the2K/17K outer rectangle and its finite endpoint-exchange reversal, but change the middle cross span from17K+138 to17K+142. Local138→140 does not describe expansion of that whole cross span. No affine map fixing both outer endpoints can move an interior point.','scope':'The endpoint-exchange sum is a diagnostic relation already fixed by the source corners, not an adopted global reflection axis. Segment ratio229/230 is diagnostic only.'}