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

def clauses(path):
    f = lzma.open(path, 'rt') if path.endswith('.xz') else open(path)
    out=[]; n=0; cur=[]
    with f:
        for line in f:
            if not line or line[0] in 'c%': continue
            if line[0]=='p': n=int(line.split()[2]); continue
            for t in line.split():
                l=int(t)
                if l==0:
                    if cur: out.append(tuple(cur)); cur=[]
                else: cur.append(l)
    return n,out

n,cs=clauses(sys.argv[1])
asg=[None]*(n+1)
for line in open(sys.argv[2]):
    if not line.startswith('v '): continue
    for t in line.split()[1:]:
        l=int(t)
        if l==0: continue
        v=abs(l)
        if v<=n: asg[v]=l>0
missing=[i for i in range(1,n+1) if asg[i] is None]
bad=[]
for i,c in enumerate(cs):
    if not any(asg[abs(l)] == (l>0) for l in c):
        bad.append((i,c)); break
print('missing',len(missing),'bad',len(bad))
sys.exit(1 if missing or bad else 0)
