import lzma,sys,itertools,collections
path=sys.argv[1]
clauses=[]; n=0
with lzma.open(path,'rt') as f:
 for line in f:
  if line[0]=='p': n=int(line.split()[2]); continue
  if line[0]=='c': continue
  lits=[int(x) for x in line.split() if x!='0']
  if lits: clauses.append(lits)
neg=set(); cand=[]
for idx,c in enumerate(clauses):
 if len(c)==2 and c[0]<0 and c[1]<0:
  a,b=sorted([-c[0],-c[1]]); neg.add((a,b))
 elif 2<=len(c)<=192 and all(x>0 for x in c): cand.append(idx)
groups=[]; used=set()
for idx in cand: # original order
 c=clauses[idx]; ok=all((min(a,b),max(a,b)) in neg for a,b in itertools.combinations(c,2))
 if ok and not any(v in used for v in c):
  gi=len(groups); groups.append(c)
  for v in c: used.add(v)
vargrp={v:i for i,g in enumerate(groups) for v in g}
print('groups',len(groups),collections.Counter(map(len,groups)), 'covered',len(vargrp), 'n',n)
for i,g in enumerate(groups[:80]): print(i,len(g),g[:8],g[-3:])
print('non exact samples')
for idx,c in enumerate(clauses):
 if idx in cand and all((min(a,b),max(a,b)) in neg for a,b in itertools.combinations(c,2)): continue
 if len(c)>2:
  print(idx,len(c),c, [(abs(l),vargrp.get(abs(l))) for l in c])
  if idx>300: break
