#!/usr/bin/env python3
import itertools
import lzma
import sys
from collections import Counter


def edge_list(n):
    return [(i, j) for i in range(n) for j in range(i + 1, n)]


def read(path):
    op = lzma.open if path.endswith(".xz") else open
    with op(path, "rt") as f:
        clauses = []
        nv = 0
        for line in f:
            if not line or line[0] in "c%0":
                continue
            if line.startswith("p "):
                nv = int(line.split()[2])
            else:
                lits = [int(x) for x in line.split() if x != "0"]
                if lits:
                    clauses.append(lits)
        return nv, clauses


def main():
    for path in sys.argv[1:]:
        nv, clauses = read(path)
        n = 0
        while n * (n - 1) // 2 < nv:
            n += 1
        edges = edge_list(n)
        sizes = Counter(len(c) for c in clauses)
        signs = Counter(tuple(sorted(set(x > 0 for x in c))) for c in clauses)
        print(path, "vars", nv, "n", n, "clauses", len(clauses), "sizes", dict(sizes), "signs", signs)
        for c in clauses[:3]:
            deg = Counter()
            for lit in c:
                a, b = edges[abs(lit) - 1]
                deg[a] += 1
                deg[b] += 1
            print(" ", c[:4], "...", sorted(deg.values()), sorted(deg.items()))


if __name__ == "__main__":
    main()
