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

def read(path):
    op=lzma.open if path.endswith('.xz') else open
    clauses=[]; nv=0
    with op(path,'rt') as f:
        for line in f:
            if not line or line[0] in 'c%': continue
            if line[0]=='p': nv=int(line.split()[2]); continue
            xs=[int(x) for x in line.split() if x!='0']
            if xs: clauses.append(xs)
    return nv,clauses

def primary(clauses):
    for c in clauses:
        if len(c)>=20 and all(c[i]==-(i+1) for i in range(len(c))): return len(c)
    return 0

def eqtail(clauses):
    idx=len(clauses); rev=[]
    while idx>=4:
        c1,c2,c3,c4=clauses[idx-4:idx]
        if not (len(c1)==len(c2)==3 and len(c3)==len(c4)==2): break
        a,b,d=c1[0],c1[1],-c1[2]
        if c2==[-a,-b,-d] and c3==[a,-b] and c4==[-a,b]:
            rev.append((a,b)); idx-=4
        else: break
    return idx, list(reversed(rev))

def eval_lit(lit,asg):
    a=asg.get(abs(lit),0)
    if a==0: return 0
    val=a>0
    if lit<0: val=not val
    return 1 if val else -1

def setlit(lit,asg):
    v=abs(lit); val=1 if lit>0 else -1
    if asg.get(v,0)==-val: return False
    asg[v]=val; return True

def prop(clauses, upto, asg):
    ch=True; rounds=0
    while ch:
        ch=False; rounds+=1
        if rounds>100000: raise RuntimeError('rounds')
        for c in clauses[:upto]:
            sat=False; un=0; last=0
            for lit in c:
                lv=eval_lit(lit,asg)
                if lv>0: sat=True; break
                if lv==0: un+=1; last=lit
            if sat: continue
            if un==0: return False
            if un==1:
                old=asg.get(abs(last),0)
                if not setlit(last,asg): return False
                if asg.get(abs(last),0)!=old: ch=True
    return True

def diff(nv,clauses,end,pairs,chosen):
    asg={}
    for i,x in enumerate(chosen,1): setlit(i if x else -i,asg)
    if not prop(clauses,end,asg): return None
    l=r=0
    for i,(a,b) in enumerate(pairs):
        va=eval_lit(a,asg); vb=eval_lit(b,asg)
        if va==0 or vb==0: return None
        if va>0: l|=1<<i
        if vb>0: r|=1<<i
    return l-r

for fn in sys.argv[1:]:
    nv,cla=read(fn); n=primary(cla); end,pairs=eqtail(cla); k=n//2
    base=[1 if i<k else 0 for i in range(n)] # 0-index, first k selected
    db=diff(nv,cla,end,pairs,base)
    rel=[0]*n; anchor=k; pivot=0
    for i in range(k):
        cur=base[:]; cur[i]=0; cur[anchor]=1
        d=diff(nv,cla,end,pairs,cur); rel[i]=-(d-db)//2
    for j in range(k,n):
        cur=base[:]; cur[pivot]=0; cur[j]=1
        d=diff(nv,cla,end,pairs,cur); rel[j]=rel[pivot]+(d-db)//2
    mn=min(rel); w=[x-mn for x in rel]; total=sum(w)
    print(fn.split('/')[-1], 'n',n,'bits',len(pairs),'mn',mn,'max',max(rel),'normsum',total,'parity',total&1,'target',total//2,'maxw',max(w))
