#!/usr/bin/env python3 from sys import argv inp = {int(x.split()[1]): [{a.split()[1]: int(a.split()[0]) for a in z.split(",")} for z in y.split(";")] for x, y in map(lambda x: x.split(":"), open(argv[1]).readlines())} print(sum([x for x, y in inp.items() if all([z.get("red", 0) <= 12 and z.get("green", 0) <= 13 and z.get("blue", 0) <= 14 for z in y])])) print(sum(max(map(lambda x: x.get("red", 0), y)) * max(map(lambda x: x.get("green", 0), y)) * max(map(lambda x: x.get("blue", 0), y)) for x, y in inp.items()))