25 lines
622 B
Python
25 lines
622 B
Python
import fileinput
|
|
from collections import deque
|
|
|
|
def main():
|
|
part1 = 0
|
|
part2 = 0
|
|
|
|
for line in fileinput.input():
|
|
values = deque(int(t) for t in line.split())
|
|
|
|
stack = [values]
|
|
while any(values):
|
|
values = deque(values[i + 1] - values[i] for i in range(len(values) - 1))
|
|
stack.append(values)
|
|
|
|
for i in range(len(stack) - 1, 0, -1):
|
|
stack[i - 1].append(stack[i - 1][-1] + stack[i][-1])
|
|
stack[i - 1].appendleft(stack[i - 1][0] - stack[i][0])
|
|
|
|
part1 += stack[0][-1]
|
|
part2 += stack[0][0]
|
|
|
|
print(part1, part2)
|
|
|
|
main()
|