import sys,lzma,random
for path in sys.argv[1:]:
 op=lzma.open if path.endswith('.xz') else open; clauses=[]
 for line in op(path,'rt'):
  if line.startswith('c') or line.startswith('p'): continue
  xs=list(map(int,line.split()));
  if xs and xs[-1]==0: xs=xs[:-1]
  if xs: clauses.append(xs)
 cover=[set(c) for c in clauses if len(c)>4 and all(x>0 for x in c)]
 best=[]
 for t in range(10000):
  used=set(); pack=[]
  order=list(range(len(cover)))
  random.shuffle(order)
  order.sort(key=lambda i: len(cover[i])+random.random()*5)
  for i in order:
   if cover[i].isdisjoint(used):
    pack.append(i); used |= cover[i]
  if len(pack)>len(best): best=pack; print(path.split('/')[-1],len(best),file=sys.stderr)
 print('FINAL',path.split('/')[-1],len(best),best[:20])
