#!/usr/bin/env python3 import sys import re enabled =True t = 0 r = re.compile('(?:do\(\)|don\'t\(\)|mul\((\d{1,3}),(\d{1,3})\))') for l in sys.stdin: for m in r.finditer(l): op = m.group(0).split("(")[0] if op == "do": enabled = True elif op == "don't": enabled = False elif enabled: t += int(m.group(1)) * int(m.group(2)) print(t)