#!/usr/bin/env python3
import lzma,sys,collections,re
fn=sys.argv[1]
openfn=lzma.open if fn.endswith('.xz') else open
cla=[]; nv=nc=0
with openfn(fn,'rt') as f:
  for line in f:
    if not line or line[0] in 'c%': continue
    if line[0]=='p':
      p=line.split(); nv=int(p[2]); nc=int(p[3]); continue
    xs=[int(x) for x in line.split() if x!='0']
    if xs: cla.append(tuple(xs))
print('nv nc read',nv,nc,len(cla))
# unit lits
print('units', [c[0] for c in cla if len(c)==1][:80])
# vars in long clauses
for c in cla:
  if len(c)>10: print('long',len(c),c[:10],c[-10:])
# binary equivalences a<->b and neg eqs
bins=set(c for c in cla if len(c)==2)
eq=[]; neq=[]
for a,b in list(bins):
  if (-a,-b) in bins: neq.append((a,b)) # a -> not b and b -> not a? clause a b, -a -b means xor true
  if (-a,b) in bins and (a,-b) in bins: pass
# detect clauses x y -z etc for AND/OR/XOR candidates nearby
# print first 300 clauses with index and size
for i,c in enumerate(cla[:260]): print(i,len(c),c)
