import sys,lzma,random,time,collections

def read(path):
    data=lzma.open(path,'rt') if path.endswith('.xz') else open(path)
    cls=[]; n=0
    for line in data:
        if not line or line[0] in 'c%0': continue
        if line[0]=='p':
            sp=line.split(); n=int(sp[2]); continue
        lits=list(map(int,line.split()))
        if lits and lits[-1]==0: lits.pop()
        if lits: cls.append(lits)
    return n,cls

def simplify(n,cls):
    assign=[0]*(n+1)
    pos=[[] for _ in range(n+1)]; neg=[[] for _ in range(n+1)]
    for i,c in enumerate(cls):
        for l in c:
            (pos if l>0 else neg)[abs(l)].append(i)
    active=[True]*len(cls); rem=[len(c) for c in cls]
    q=collections.deque([c[0] for c in cls if len(c)==1])
    conflict=False
    while q:
        lit=q.popleft(); v=abs(lit); val=1 if lit>0 else -1
        if assign[v]:
            if assign[v]!=val: conflict=True; break
            continue
        assign[v]=val
        satlist=pos[v] if val==1 else neg[v]
        unsatlist=neg[v] if val==1 else pos[v]
        for ci in satlist: active[ci]=False
        for ci in unsatlist:
            if not active[ci]: continue
            rem[ci]-=1
            if rem[ci]==0: conflict=True; break
            if rem[ci]==1:
                for l in cls[ci]:
                    if assign[abs(l)]==0:
                        q.append(l); break
        if conflict: break
    print('assigned units',sum(1 for x in assign if x),'conflict',conflict,'active',sum(active))
    # count unit polarities assignment all false/true remaining?
    return assign

for p in sys.argv[1:]:
    n,cls=read(p); print('\n',p,n,len(cls)); simplify(n,cls)
