#!/usr/bin/env python3 from functools import reduce import re, sys import sys def awl(p): l = [set(x) for x in p.split()] return len(set.intersection(*l)) fn = sys.argv[1] if len(sys.argv) > 1 else 'input6' with open(fn) as f: pgphs = f.read().split('\n\n') lines = [l.strip() for l in f.readlines()] print(sum(len(set(re.sub('\n', '', p))) for p in pgphs)) print(sum(awl(p) for p in pgphs))