#!/usr/bin/env python3
import sys,lzma,time
from collections import deque

def lit_id(l):
    v=abs(l)-1
    return 2*v + (0 if l>0 else 1)
def neg_id(i): return i^1

def openf(p): return lzma.open(p,'rt') if p.endswith('.xz') else open(p)
for path in sys.argv[1:]:
    t=time.time(); n=0; edges=[]; non2=0
    with openf(path) as f:
        for line in f:
            if not line or line[0]=='c': continue
            if line[0]=='p': n=int(line.split()[2]); continue
            arr=[int(x) for x in line.split() if x!='0']
            if len(arr)==2:
                a,b=arr; ai=lit_id(a); bi=lit_id(b)
                edges.append((ai^1,bi)); edges.append((bi^1,ai))
            else: non2+=1
    N=2*n; g=[[] for _ in range(N)]; rg=[[] for _ in range(N)]
    for u,v in edges: g[u].append(v); rg[v].append(u)
    seen=bytearray(N); order=[]
    for s in range(N):
        if seen[s]: continue
        stack=[(s,0)]; seen[s]=1
        while stack:
            u,i=stack[-1]
            if i < len(g[u]):
                v=g[u][i]; stack[-1]=(u,i+1)
                if not seen[v]: seen[v]=1; stack.append((v,0))
            else:
                order.append(u); stack.pop()
    comp=[-1]*N; cid=0
    for s in reversed(order):
        if comp[s]!=-1: continue
        comp[s]=cid; st=[s]
        while st:
            u=st.pop()
            for v in rg[u]:
                if comp[v]==-1: comp[v]=cid; st.append(v)
        cid+=1
    bad=[i+1 for i in range(n) if comp[2*i]==comp[2*i+1]]
    print(path.split('/')[-1], 'n',n,'edges',len(edges),'non2',non2,'2sat_unsat',bool(bad),'badvars',len(bad),'first',bad[:5], 'time',round(time.time()-t,2), flush=True)
