#!/usr/bin/env python3 import sys def parse(): cases = [] for l in sys.stdin: target = int(l.split(":")[0]) nums = [int(x) for x in l.split(" ")[1:]] cases.append((target, nums)) return cases def check(case): target, nums = case # Since we don't need to know what operators we use, # we can just recursively check the patterns) def rchk(run, rem): if not rem: return run == target return rchk(run * rem[0], rem[1:]) or rchk(run + rem[0], rem[1:]) if rchk(nums[0], nums[1:]): return target return 0 if __name__ == '__main__': cases = parse() tot = 0 for c in cases: tot += check(c) print(tot)