-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy path07.py
More file actions
27 lines (24 loc) · 663 Bytes
/
07.py
File metadata and controls
27 lines (24 loc) · 663 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
from operator import *
def concat(a, b):
return int(str(a) + str(b))
s1 = s2 = 0
for line in open(0):
first, rest = line.split(": ")
n = [int(a) for a in rest.split()]
first = int(first)
repeat = len(n) - 1
for mask in range(3**repeat):
s = n[0]
for_part1 = True
for i in range(repeat):
mask, index = divmod(mask, 3)
for_part1 &= index != 2
op = [add, mul, concat][index]
s = op(s, n[i+1])
if s > first:
break
if s == first:
s1 += first * for_part1
s2 += first
break
print(s1, s2, sep="\n")