#!/usr/bin/env python3
import sys,lzma,time,collections

def op(p): return lzma.open(p,'rt') if p.endswith('.xz') else open(p)
for path in sys.argv[1:]:
 t=time.time(); n=0; rows=[]; bins=[]
 with op(path) as f:
  for line in f:
   if not line or line[0]=='c': continue
   if line[0]=='p': n=int(line.split()[2]); continue
   arr=[int(x) for x in line.split() if x!='0']
   if len(arr)==2: bins.append(tuple(arr))
   elif len(arr)>0: rows.append(arr)
 sel=[0]*(n+1); rowof=[-1]*(n+1); dup=0; badrow=0
 for ri,r in enumerate(rows):
  seen=set()
  for lit in r:
   v=abs(lit)
   if v in seen: badrow+=1
   seen.add(v)
   if sel[v]!=0: dup+=1
   else: sel[v]=lit; rowof[v]=ri
 missing=sum(1 for v in range(1,n+1) if sel[v]==0)
 row_pairs=sum(len(r)*(len(r)-1)//2 for r in rows)
 internal=external=other=0
 par=collections.Counter()
 # sample conflicts by binary whose literals are both negated selected
 for a,b in bins:
  va,vb=abs(a),abs(b)
  ok=(sel[va]!=0 and sel[vb]!=0 and a==-sel[va] and b==-sel[vb])
  if ok:
   if rowof[va]==rowof[vb]: internal+=1
   else: external+=1
  else: other+=1; par[(a==sel[va] if sel[va] else None,b==sel[vb] if sel[vb] else None)]+=1
 print(path.split('/')[-1], 'n',n,'rows',len(rows),'rowlen',collections.Counter(map(len,rows)), 'missing',missing,'dup',dup,'badrow',badrow)
 print(' bins',len(bins),'internal',internal,'row_pairs',row_pairs,'external',external,'other',other,'time',round(time.time()-t,2), 'otherpar',par.most_common(4), flush=True)
