#!/usr/bin/env python3
import sys,lzma,collections,os
from pathlib import Path

def open_cnf(path):
    return lzma.open(path,'rt') if str(path).endswith('.xz') else open(path)

for path in sys.argv[1:]:
    n=m=0; dist=collections.Counter(); pos=collections.Counter(); neg=collections.Counter(); lits=0
    units=[]; binaries=[]; clauses=[]
    with open_cnf(path) as f:
        for line in f:
            if not line or line[0]=='c': continue
            if line[0]=='p':
                parts=line.split(); n=int(parts[2]); m=int(parts[3]); continue
            arr=[int(x) for x in line.split() if x!='0']
            if not arr: continue
            dist[len(arr)]+=1; lits+=len(arr)
            for l in arr:
                (pos if l>0 else neg)[abs(l)]+=1
    pure=sum(1 for v in range(1,n+1) if (pos[v]==0)^(neg[v]==0))
    unused=sum(1 for v in range(1,n+1) if pos[v]+neg[v]==0)
    print(Path(path).name, 'n',n,'m',m,'dist',dict(sorted(dist.items())),'avgdeg',round(lits/n,2),'pure',pure,'unused',unused)
    deg=[pos[v]+neg[v] for v in range(1,n+1)]
    print(' deg min/max/top', min(deg), max(deg), sorted(deg, reverse=True)[:10])
    print(' pos total',sum(pos.values()),'neg total',sum(neg.values()), 'balanced vars',sum(1 for v in range(1,n+1) if pos[v]==neg[v]))
