import sys from lib import * data = open(0).read().strip() first = False bots = {} outputs = {} while True: if not first and 0 in outputs and 1 in outputs and 2 in outputs: print(outputs[0] * outputs[1] * outputs[2]) sys.exit(0) for line in data.splitlines(): ints = str_to_ints(line) if len(ints) == 2: val, bot = ints if bot in bots: if val not in bots[bot]: bots[bot].append(val) else: bots[bot] = [val] elif len(ints) == 3: bot, lobot, hibot = ints if bot in bots and len(bots[bot]) == 2: loval = min(bots[bot]) hival = max(bots[bot]) bots[bot] = [] if first and loval == 17 and hival == 61: print(bot) sys.exit(0) if "low to bot" in line: if lobot in bots: if loval not in bots[lobot]: bots[lobot].append(loval) else: bots[lobot] = [loval] if "high to bot" in line: if hibot in bots: if hival not in bots[hibot]: bots[hibot].append(hival) else: bots[hibot] = [hival] if "low to output" in line: outputs[lobot] = loval if "high to output" in line: outputs[hibot] = hival else: assert False