···33from collections import defaultdict
44from utils import parse_line, mul
5566-76BOTS = defaultdict(list)
87OUTPUTS = defaultdict(list)
99-1010-inst = [line.strip() for line in fileinput.input()]
88+INSTRUCTIONS = [line.strip() for line in fileinput.input()]
1191212-while inst:
1010+while INSTRUCTIONS:
1311 temp = []
14121515- for line in inst:
1313+ for line in INSTRUCTIONS:
1614 if 'value' in line:
1715 val, bot = [int(x) for x in re.findall(r'(\d+)', line)]
1816 BOTS[bot].append(val)
···3028 l, h = sorted(BOTS[bot][:2])
3129 BOTS[bot] = []
32303333- if low_t == 'bot':
3434- BOTS[low].append(l)
3535- else:
3636- OUTPUTS[low].append(l)
3131+ (BOTS if low_t == 'bot' else OUTPUTS)[low].append(l)
3232+ (BOTS if high_t == 'bot' else OUTPUTS)[high].append(h)
37333838- if high_t == 'bot':
3939- BOTS[high].append(h)
4040- else:
4141- OUTPUTS[high].append(h)
4242-4343- inst = temp
3434+ INSTRUCTIONS = temp
4435 temp = []
45364637product = mul(OUTPUTS[i][0] for i in range(3))