#!/usr/bin/env python3
import lzma, sys, collections, os, re
for f in sys.argv[1:]:
    with lzma.open(f,'rt') as fh:
        header=fh.readline().split(); V=int(header[2]); C=int(header[3])
        first=fh.readline().split(); aux_start=abs(int(first[2])); P=aux_start-1
        # process first clause plus rest
        def lits_from(parts): return [int(x) for x in parts if x!='0']
        stats=collections.Counter(); ponly=0; mix=0; auxonly=0; maxp=0; primary_vars=set(); pclauses=[]
        for parts in [first]+[line.split() for line in fh]:
            lits=lits_from(parts)
            if not lits: continue
            is_p=[abs(x)<=P for x in lits]
            if all(is_p):
                ponly+=1; stats[len(lits)]+=1; pclauses.append(tuple(lits));
                for x in lits: primary_vars.add(abs(x)); maxp=max(maxp,abs(x))
            elif any(is_p): mix+=1
            else: auxonly+=1
        print(os.path.basename(f),'V',V,'C',C,'P',P,'primary-only',ponly,'mix',mix,'auxonly',auxonly,'pvars-in-ponly',len(primary_vars),'maxp',maxp)
        print(' len',dict(sorted(stats.items())))
        print(' first primary-only clauses:')
        for cl in pclauses[:20]: print(' ',cl)
        print(' last primary-only clauses:')
        for cl in pclauses[-20:]: print(' ',cl)
