#!/usr/bin/env python3
"""METR23 factual-only complete-source reproduction, Python standard library.
The algebra below is copied by value from the author's separately written
full-block/Schur Fraction reference. This is public reproducible code, not an
additional independent oracle. The source transformations/CSV study are new.
It reads only three factual CSVs and never imports the web engine, an answer
JSON or previous derived results. Native-file decoding is archived separately.
"""
from pathlib import Path
import argparse,csv,json,hashlib,sys
sys.set_int_max_str_digits(0)

"""Separate author reference: full raw 2SLS block normal equations;
panel raw crossproducts minus entity-block Schur complements.
No candidate JS/public program/answer values imported or executed here.
"""
from fractions import Fraction as Q
from collections import defaultdict
def f(v):return None if v is None else Q(str(v))
def total(v):return sum(v,Q(0))
def dot(a,b):return total(x*y for x,y in zip(a,b))
def reduce(A):
 n=len(A);B=[r[:]+[Q(i==j)for j in range(n)]for i,r in enumerate(A)];rank=0;piv=[]
 for col in range(n):
  choices=[i for i in range(rank,n)if B[i][col]]
  if not choices:continue
  pivot=choices[-1];B[rank],B[pivot]=B[pivot],B[rank];den=B[rank][col];B[rank]=[x/den for x in B[rank]]
  for i in range(n):
   if i!=rank:
    factor=B[i][col]
    if factor:B[i]=[x-factor*y for x,y in zip(B[i],B[rank])]
  piv.append(col);rank+=1
 def solve(rhs):
  values=[dot(r[n:],rhs)for r in B]
  assert all(v==0 for v in values[rank:]);out=[Q(0)]*n
  for i,j in enumerate(piv):out[j]=values[i]
  return out
 free=[j for j in range(n)if j not in piv];basis=[]
 for j in free:
  v=[Q(i==j)for i in range(n)]
  for i,k in enumerate(piv):v[k]=-B[i][j]
  basis.append(v)
 return dict(rank=rank,pivots=piv,free=free,nullspace=basis,solve=solve)
def projection(Z,Y,p=None):
 p=p if p is not None else len(Z[0])if Z else 0;G=[[total(r[j]*r[k]for r in Z)for k in range(p)]for j in range(p)];dec=reduce(G);results=[]
 for values in Y:
  h=[total(r[j]*v for r,v in zip(Z,values))for j in range(p)];b=dec['solve'](h);fitted=[dot(r,b)for r in Z];residual=[v-u for v,u in zip(values,fitted)];results.append(dict(rhs=h,particular=b,fitted=fitted,residuals=residual,orthogonality=[total(r[j]*u for r,u in zip(Z,residual))for j in range(p)]))
 return dict(n=len(Z),columns=p,rank=dec['rank'],pivots=dec['pivots'],free=dec['free'],nullspace=dec['nullspace'],Gram=G,results=results)
def ivframe(a):
 p=len(a['rows'][0]['c'])if a['rows']else 0;q=len(a['rows'][0]['z'])if a['rows']else 1;rows=[]
 for i,r in enumerate(a['rows']):
  ident=r.get('id',i);y=f(r.get('y'));x=f(r.get('x'));c=list(map(f,r['c']));z=list(map(f,r['z']));eligible=all(v is not None for v in[y,x]+c+z);reason=None if eligible else'outcome-missing'if y is None else'exposure-missing'if x is None else'control-missing'if any(v is None for v in c)else'instrument-missing';rows.append(dict(index=i,id=ident,group=r.get('group',ident),y=y,x=x,c=c,z=z,eligible=eligible,reason=reason))
 return rows,p,q
def partial(a):
 rows,p,q=ivframe(a);rr=[r for r in rows if r['eligible']];fit=projection([[Q(1)]+r['c']for r in rr],[[r['y']for r in rr],[r['x']for r in rr]]+[[r['z'][j]for r in rr]for j in range(q)],p+1);by={r['index']:i for i,r in enumerate(rr)}
 return dict(sourceRows=len(rows),n=len(rr),p=p,q=q,controlProjection=fit,rows=[r if r['index']not in by else dict(r,yResidual=fit['results'][0]['residuals'][by[r['index']]],xResidual=fit['results'][1]['residuals'][by[r['index']]],zResidual=[v['residuals'][by[r['index']]]for v in fit['results'][2:]])for r in rows])
def variances(rows):
 groups={}
 for r in rows:
  key=(type(r['group']).__name__,r['group'])
  if key not in groups:groups[key]=dict(group=r['group'],scoreSum=Q(0))
  groups[key]['scoreSum']+=r['influence']
 return dict(rowHC0Variance=total(r['influence']**2 for r in rows),groupHC0Variance=total(r['scoreSum']**2 for r in groups.values()),clusterScores=list(groups.values()),reportingGroups=len(groups))
def iv(a):
 out=partial(a);rr=[r for r in out['rows']if r['eligible']];n=len(rr)
 if not rr:return dict(out,status='undefined-empty-frame',OLS=None,IV=None)
 C=[[Q(1)]+r['c']for r in rr];X=[r+[v['x']]for r,v in zip(C,rr)];A=[r+v['z']for r,v in zip(C,rr)];Y=[r['y']for r in rr];x=[r['x']for r in rr];firstFull=projection(A,[x]);xhat=firstFull['results'][0]['fitted'];PZX=[c+[v]for c,v in zip(C,xhat)];k=len(X[0]);G=[[total(r[j]*p[i]for r,p in zip(X,PZX))for i in range(k)]for j in range(k)];rhs=[total(p[j]*y for p,y in zip(PZX,Y))for j in range(k)];dec=reduce(G);coef=dec['solve'](rhs);identified=all(v[-1]==0 for v in dec['nullspace']);beta=coef[-1]if identified else None;H=[[total(r[j]*r[i]for r in X)for i in range(k)]for j in range(k)];h=[total(r[j]*y for r,y in zip(X,Y))for j in range(k)];olsDec=reduce(H);olsCoef=olsDec['solve'](h);olsID=all(v[-1]==0 for v in olsDec['nullspace']);olsBeta=olsCoef[-1]if olsID else None;ols=None;ivResult=None;yr=[r['yResidual']for r in rr];xr=[r['xResidual']for r in rr];Zr=[r['zResidual']for r in rr];fp=projection(Zr,[xr]);firstR=fp['results'][0]['fitted'];Sxx=dot(xr,xr);Sxy=dot(xr,yr);B=dot(firstR,xr);SSEfirst=total((v-w)**2 for v,w in zip(x,xhat));rankZ=firstFull['rank']-out['controlProjection']['rank'];dfFirst=n-firstFull['rank'];F=(B/rankZ)/(SSEfirst/dfFirst)if rankZ and dfFirst>0 and SSEfirst else None;inf=bool(rankZ and dfFirst>0 and not SSEfirst and B>0);withrows=[]
 if olsID:
  ev=[Q(0)]*k;ev[-1]=Q(1);g=olsDec['solve'](ev);rrOLS=[]
  for r,z in zip(rr,X):
   residual=r['y']-dot(z,olsCoef);w=dot(z,g);rrOLS.append(dict(id=r['id'],group=r['group'],residual=residual,linearWeight=w,influence=w*residual))
  ols=dict(beta=olsBeta,Sxx=Sxx,Sxy=Sxy,rows=rrOLS,**variances(rrOLS))
 if identified:ev=[Q(0)]*k;ev[-1]=Q(1);v=dec['solve'](ev)
 for i,(r,z,pz)in enumerate(zip(rr,X,PZX)):
  residual=r['y']-dot(z,coef)if identified else None;w=dot(pz,v)if identified else None;withrows.append(dict(r,firstFitted=firstR[i],firstResidual=x[i]-xhat[i],structuralResidual=residual,fittedOriginal=None if residual is None else r['y']-residual,linearWeight=w,influence=None if residual is None else w*residual))
 if identified:ivResult=dict(beta=beta,denominator=B,numerator=dot(firstR,yr),controlParticular=coef[:-1],controlNullspace=out['controlProjection']['nullspace'],SSE=total(r['structuralResidual']**2 for r in withrows),residualDF=n-out['controlProjection']['rank']-int(Sxx!=0),**variances(withrows))
 by={r['index']:r for r in withrows};return dict(out,status='identified-finite-2SLS'if identified else'exposure-not-identified',OLS=ols,IV=ivResult,firststage=dict(projection=fp,rank=rankZ,Sxx=Sxx,explainedSumSquares=B,SSE=SSEfirst,partialR2=B/Sxx if Sxx else None,residualDF=dfFirst,F=F,FPositiveInfinity=inf),rows=[by.get(r['index'],r)for r in out['rows']])
def panel(a):
 raw=a['rows'];mode=a.get('mode','entity');p=len(raw[0]['c'])if raw else 0;rows=[]
 for i,r in enumerate(raw):
  y=f(r.get('y'));x=f(r.get('x'));c=list(map(f,r['c']));eligible=all(v is not None for v in[y,x]+c);rows.append(dict(index=i,id=r.get('id',i),entity=r['entity'],group=r['entity'],time=r['time'],y=y,x=x,c=c,eligible=eligible,reason=None if eligible else'outcome-missing'if y is None else'exposure-missing'if x is None else'control-missing'))
 rr=[r for r in rows if r['eligible']];times=sorted({r['time']for r in rr});allTimes=sorted({r['time']for r in rows});step=a.get('step',1);origin=a.get('origin',allTimes[0]if allTimes else 0)
 if not rr:return dict(status='undefined-empty-frame',mode=mode,sourceRows=len(rows),n=0,rows=rows)
 groups=defaultdict(list)
 for r in rr:groups[(type(r['entity']).__name__,r['entity'])].append(r)
 E=len(groups);timeColumns=times[1:]if mode=='twoway'else[]
 # Raw sufficient crossproducts followed by the entity-block Schur complement.
 vectors=[[r['y'],r['x']]+([Q(1)]if mode=='pooled'else[])+r['c']+[Q(r['time']==t)for t in timeColumns]for r in rr];d=len(vectors[0]);cross=[[total(z[i]*z[j]for z in vectors)for j in range(d)]for i in range(d)];byIndex={r['index']:z for r,z in zip(rr,vectors)};means={};sumBy={}
 for key,rs in groups.items():
  ss=[total(byIndex[r['index']][i]for r in rs)for i in range(d)];sumBy[key]=ss;means[key]=dict(entity=rs[0]['entity'],n=len(rs),y=total(r['y']for r in rs)/len(rs),x=total(r['x']for r in rs)/len(rs),c=[total(r['c'][j]for r in rs)/len(rs)for j in range(p)])
  if mode!='pooled':
   for i in range(d):
    for j in range(d):cross[i][j]-=ss[i]*ss[j]/len(rs)
 G=[r[2:]for r in cross[2:]];dec=reduce(G);hy=[r[0]for r in cross[2:]];hx=[r[1]for r in cross[2:]];cy=dec['solve'](hy);cx=dec['solve'](hx);Sxx=cross[1][1]-dot(hx,cx);Sxy=cross[0][1]-dot(hx,cy);beta=Sxy/Sxx if Sxx else None;out=[];controlValues=[];ys=[];xs=[]
 for r,z in zip(rr,vectors):
  key=(type(r['entity']).__name__,r['entity']);zz=z if mode=='pooled'else[v-u/len(groups[key])for v,u in zip(z,sumBy[key])];cr=zz[2:];yr=zz[0]-dot(cr,cy);xr=zz[1]-dot(cr,cx);residual=None if beta is None else yr-beta*xr;w=None if beta is None else xr/Sxx;out.append(dict(r,yTransformed=zz[0],xTransformed=zz[1],controlDesign=cr,yResidual=yr,xResidual=xr,residual=residual,fittedOriginal=None if residual is None else r['y']-residual,linearWeight=w,influence=None if residual is None else w*residual));controlValues.append(cr);ys.append(zz[0]);xs.append(zz[1])
 coeffProjection=projection(controlValues,[ys,xs]);assert coeffProjection['Gram']==G;by={r['index']:r for r in out};absorbed=E if mode!='pooled'else 0;designRank=absorbed+dec['rank']+int(Sxx!=0);variance=variances(out)if beta is not None else dict(rowHC0Variance=None,groupHC0Variance=None,clusterScores=[],reportingGroups=E)
 return dict(status='identified-finite-panel-slope'if beta is not None else'exposure-not-identified',mode=mode,sourceRows=len(rows),n=len(rr),entities=E,periods=len(times),step=step,origin=origin,beta=beta,Sxx=Sxx,Sxy=Sxy,absorbedEntityRank=absorbed,remainingControlRank=dec['rank'],designRank=designRank,residualDF=len(rr)-designRank,controlProjection=coeffProjection,entityMeans=list(means.values()),timeIndicatorYears=timeColumns,SSE=None if beta is None else total(r['residual']**2 for r in out),rows=[by.get(r['index'],r)for r in rows],**variance)

def read_csv(p):
 with p.open(encoding='utf8',newline='')as fp:return list(csv.DictReader(fp))
def token(s):return None if s in ['','.']or s is None else Q(s)
def encode(v):
 if v is None:return ''
 if isinstance(v,bool):return 'true'if v else'false'
 if isinstance(v,(list,dict)):return json.dumps(v,ensure_ascii=False,separators=(',',':'),default=str)
 return str(v)
def write_csv(out,name,rows,fields=None):
 assert rows or fields,name
 with(out/name).open('w',encoding='utf8',newline='')as fp:
  writer=csv.DictWriter(fp,fieldnames=fields or list(rows[0]));writer.writeheader();writer.writerows({k:encode(v)for k,v in r.items()}for r in rows)
def source_frames(source):
 person=read_csv(source/'actual3613-NLS-all52-native-fields.csv');country=read_csv(source/'actual512-WB-twoindicators-2009-2024.csv');company=read_csv(source/'actual1031-abdata-all30-native-fields.csv')
 controls=['potentialExperience','potentialExperienceSquaredOver100','black','smsa76r','reg76r','smsa66r']+['reg66'+str(i)for i in range(1,9)];P=[]
 for r in person:
  x=token(r['ed76']);age=token(r['age76']);experience=None if age is None or x is None else age-x-6
  c=[experience,None if experience is None else experience**2/100]+[token(r[k])for k in controls[2:]];z=[token(r['nearc4']),token(r['nearc2'])]
  P.append(dict(id='nls:'+r['id'],group='nls:'+r['id'],sourceRow=int(r['sourceRow']),y=token(r['lwage76']),x=x,c=c,z=z))
 assert len(P)==3613 and len({r['id']for r in P})==3613 and sum(all(v is not None for v in[r['y'],r['x']]+r['c']+r['z'])for r in P)==3010
 lookup={(r['countryISO3'],int(r['year']),r['indicatorID']):r for r in country};assert len(lookup)==len(country)==512;K=[]
 for iso in sorted({r['countryISO3']for r in country}):
  for t in range(2010,2025):
   g=lookup[iso,t,'NY.GDP.MKTP.KD.ZG'];u=lookup[iso,t,'SL.UEM.TOTL.ZS'];prior=lookup[iso,t-1,'SL.UEM.TOTL.ZS'];uv=token(u['originalValueToken']);pv=token(prior['originalValueToken'])
   K.append(dict(id=f'wb:{iso}:{t}',entity='country:'+iso,time=t,y=token(g['originalValueToken']),x=None if uv is None or pv is None else uv-pv,c=[],sourceRows=[int(r['sourceRow'])for r in[g,u,prior]]))
 F=[dict(id='abdata:'+r['sourceRow'],entity='firm:'+r['id'],time=int(Q(r['year'])),y=token(r['n']),x=token(r['w']),c=[token(r['k']),token(r['ys'])],sourceRow=int(r['sourceRow']))for r in company]
 assert len(F)==1031 and len({r['entity']for r in F})==140 and len({(r['entity'],r['time'])for r in F})==1031;assert len(K)==240
 return dict(person=P,country=K,company=F),controls
def study(source,out):
 out.mkdir(parents=True,exist_ok=False);frames,controls=source_frames(source);fits=[]
 for label,q in [('nearc4',1),('both',2)]:
  # Both instruments are present on the frozen common frame before selecting a column set.
  rows=[dict(r,z=r['z'][:q])for r in frames['person']];fits.append(('person',label,iv(dict(rows=rows))))
 for kind in ['country','company']:
  for mode in ['pooled','entity','twoway']:fits.append((kind,mode,panel(dict(rows=frames[kind],mode=mode))))
 metrics=[];personrows=[];olsrows=[];panelrows=[];coefficients=[];means=[];clusters=[];points=[];links=[];sensitivity=[]
 def metric(kind,spec,key,value,unit):metrics.append(dict(kind=kind,spec=spec,metric=key,value=value,unit=unit))
 for kind,spec,v in fits:
  yunit='recordedlogwage'if kind=='person'else'GDPgrowthpercent'if kind=='country'else'storedlogemployment';xunit='schoolingyears'if kind=='person'else'unemploymentchangepp'if kind=='country'else'storedlogwage';bunit=yunit+'/'+xunit
  for key,value,unit in [('sourceRows',v['sourceRows'],'rows'),('completeRows',v['n'],'rows')]:metric(kind,spec,key,value,unit)
  if kind=='person':
   b=v['IV'];fs=v['firststage'];metric(kind,spec,'controlRank',v['controlProjection']['rank'],'directions')
   for key,value,unit in [('OLSbeta',v['OLS']['beta'],bunit),('IVbeta',b['beta'],bunit),('Sxx',fs['Sxx'],xunit+' squared'),('explainedXSS',fs['explainedSumSquares'],xunit+' squared'),('firstSSE',fs['SSE'],xunit+' squared'),('instrumentRank',fs['rank'],'directions'),('partialR2',fs['partialR2'],'dimensionless'),('firstF',fs['F'],'dimensionless'),('firstResidualDF',fs['residualDF'],'degreesoffreedom'),('structuralResidualDF',b['residualDF'],'degreesoffreedom'),('structuralSSE',b['SSE'],yunit+' squared'),('rowHC0Variance',b['rowHC0Variance'],'('+bunit+') squared'),('groupHC0Variance',b['groupHC0Variance'],'('+bunit+') squared'),('reportingGroups',b['reportingGroups'],'groups')]:metric(kind,spec,key,value,unit)
   for j,beta in enumerate(b['controlParticular']):coefficients.append(dict(kind=kind,spec=spec,control='intercept'if j==0 else controls[j-1],coefficient=beta,unit=yunit+'/declaredcontrolunit'))
   for r in v['rows']:
    personrows.append(dict(spec=spec,analysisID=r['id'],sourceRow=r['index']+1,eligible=r['eligible'],reason=r['reason'],y=r['y'],x=r['x'],controls=r['c'],instruments=r['z'],yResidual=r.get('yResidual'),xResidual=r.get('xResidual'),zResidual=r.get('zResidual'),firstFitted=r.get('firstFitted'),firstResidual=r.get('firstResidual'),structuralResidual=r.get('structuralResidual'),fittedOriginal=r.get('fittedOriginal'),linearWeight=r.get('linearWeight'),influence=r.get('influence')))
    if r['eligible']:
     for chart,x,y in [('person-'+spec+'-secondstage',r['firstFitted'],r['yResidual']),('person-'+spec+'-structural-residual',Q(r['index']+1),r['structuralResidual'])]:points.append(dict(kind=kind,chart=chart,analysisID=r['id'],series=spec,x=x,y=y))
   for r in v['OLS']['rows']:olsrows.append(dict(spec=spec,analysisID=r['id'],residual=r['residual'],linearWeight=r['linearWeight'],influence=r['influence']))
   for r in b['clusterScores']:clusters.append(dict(kind=kind,spec=spec,group=r['group'],score=r['scoreSum'],squaredScore=r['scoreSum']**2))
   if spec=='nearc4':
    rr=[r for r in v['rows']if r['eligible']];zz=[r['zResidual'][0]for r in rr];ZSS=dot(zz,zz);pi=dot(zz,[r['xResidual']for r in rr])/ZSS;delta=dot(zz,[r['yResidual']for r in rr])/ZSS
    for lo,hi in [(Q(0),Q(0)),(Q(0),Q('0.01')),(Q('-0.01'),Q('0.01'))]:
     ends=sorted([(delta-lo)/pi,(delta-hi)/pi]);sensitivity.append(dict(spec=spec,reducedForm=delta,firstStage=pi,directLower=lo,directUpper=hi,betaLower=ends[0],betaUpper=ends[1],unit=bunit,scope='Stipulateddirecteffectrange;notconfidenceinterval'))
  else:
   for key,value,unit in [('beta',v['beta'],bunit),('entities',v['entities'],'entities'),('periods',v['periods'],'periods'),('designRank',v['designRank'],'directions'),('absorbedEntityRank',v['absorbedEntityRank'],'directions'),('remainingControlRank',v['remainingControlRank'],'directions'),('residualDF',v['residualDF'],'degreesoffreedom'),('Sxx',v['Sxx'],xunit+' squared'),('Sxy',v['Sxy'],xunit+'*'+yunit),('SSE',v['SSE'],yunit+' squared'),('rowHC0Variance',v['rowHC0Variance'],'('+bunit+') squared'),('groupHC0Variance',v['groupHC0Variance'],'('+bunit+') squared'),('reportingGroups',v['reportingGroups'],'groups')]:metric(kind,spec,key,value,unit)
   for r in v['rows']:
    panelrows.append(dict(kind=kind,spec=spec,analysisID=r['id'],sourceIndex=r['index'],entity=r['entity'],time=r['time'],eligible=r['eligible'],reason=r['reason'],y=r['y'],x=r['x'],controls=r['c'],yTransformed=r.get('yTransformed'),xTransformed=r.get('xTransformed'),yResidual=r.get('yResidual'),xResidual=r.get('xResidual'),residual=r.get('residual'),fittedOriginal=r.get('fittedOriginal'),linearWeight=r.get('linearWeight'),influence=r.get('influence')))
    if r['eligible']:points.append(dict(kind=kind,chart=kind+'-'+spec+'-residual-space',analysisID=r['id'],series=r['entity'],x=r['xResidual'],y=r['yResidual']))
   for r in v['entityMeans']:means.append(dict(kind=kind,spec=spec,entity=r['entity'],n=r['n'],yMean=r['y'],xMean=r['x'],controlMeans=r['c']))
   for r in v['clusterScores']:clusters.append(dict(kind=kind,spec=spec,group=r['group'],score=r['scoreSum'],squaredScore=r['scoreSum']**2))
 for kind,rows in frames.items():
  for r in rows:
   links.append(dict(kind=kind,analysisID=r['id'],sourceRows=r.get('sourceRows',[r.get('sourceRow')]),time=r.get('time'),entity=r.get('entity'),y=r['y'],x=r['x']))
   if r['y']is not None and r['x']is not None:
    if kind=='person':
     if all(v is not None for v in r['c']+r['z']):points.append(dict(kind=kind,chart='person-native-schooling-logwage',analysisID=r['id'],series='recorded-log',x=r['x'],y=r['y']))
    else:points.append(dict(kind=kind,chart=kind+'-native-time',analysisID=r['id'],series=r['entity'],x=Q(r['time']),y=r['y']))
 tables={'computed-fit-metrics.csv':metrics,'computed-person-analysis-rows.csv':personrows,'computed-person-OLS-rows.csv':olsrows,'computed-control-coefficients.csv':coefficients,'computed-panel-analysis-rows.csv':panelrows,'computed-entity-means.csv':means,'computed-cluster-scores.csv':clusters,'computed-exclusion-ranges.csv':sensitivity,'computed-model-row-source-links.csv':links,'computed-source-chart-points.csv':points}
 for name,rows in tables.items():write_csv(out,name,rows)
 inputs=[p for p in sorted(source.glob('actual*.csv'))if p.name in ['actual3613-NLS-all52-native-fields.csv','actual512-WB-twoindicators-2009-2024.csv','actual1031-abdata-all30-native-fields.csv']]
 manifest=dict(chapter='METR-23',arithmetic='Exact Fraction on preservedfinite inputs',inputs=[dict(file=p.name,sha256=hashlib.sha256(p.read_bytes()).hexdigest())for p in inputs],sourceOnly='OnlythreefactualCSVs;noengine/model/answer/derivedCSVread',frames={k:len(v)for k,v in frames.items()},fits=len(fits),outputs=[dict(file=name,rows=len(rows),columns=len(rows[0]),bodyFields=len(rows)*len(rows[0]),sha256=hashlib.sha256((out/name).read_bytes()).hexdigest())for name,rows in tables.items()],sourceChartPoints=len(points),scope='Declaredactualfullsourceeightfits;notfullportofallgenericAPIboundaries;noglobalcausalorinferencecertificate')
 (out/'metr23-reproduction-manifest.json').write_text(json.dumps(manifest,ensure_ascii=False,indent=2)+'\n',encoding='utf8');print(json.dumps(dict(status='PASS',fits=len(fits),CSV=len(tables),fields=sum(r['bodyFields']for r in manifest['outputs']),points=len(points))))
if __name__=='__main__':
 parser=argparse.ArgumentParser(description='METR23 factual-only complete-source exact reproduction');parser.add_argument('--sources',type=Path,default=Path(__file__).resolve().parent.parent/'metr23-sources');parser.add_argument('--out',type=Path,required=True);args=parser.parse_args();study(args.sources,args.out)
