with open("input3.txt") as f: a = dict(zip(map(chr,(list(range(97,123))+list(range(65,91)))),range(1,53))) s = 0 h = [] for line in f.readlines(): h.append(set(line.strip())) if len(h) < 3: continue s += a[(h[0]&h[1]&h[2]).pop()] h = [] print(s)