#!/usr/bin/env python from sys import stdin import re def read_line(): for line in stdin: yield line sum = 0 for line in read_line(): t1 = line.split(":", 2) num = int(t1[0].split(" ")[-1]) rounds = t1[1].split(";") correct = True for round in rounds: red = 0 green = 0 blue = 0 m = re.search("(\d+) blue", round) if m: blue = int(m.group(1)) m = re.search("(\d+) red", round) if m: red = int(m.group(1)) m = re.search("(\d+) green", round) if m: green = int(m.group(1)) if red > 12: correct = False if green > 13: correct = False if blue > 14: correct = False if correct: sum += num print(sum)