blob: 3d16c5c3336efdcf2f4e344471852de451d7971a (
plain) (
blame)
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
28
29
30
31
32
|
#!/usr/bin/python3
data = []
try:
while True:
data.append([[x for x in map(int, input().split(" "))]])
except EOFError:
pass
s = 0
for d in data:
while len(set(d[-1])) != 1 or d[-1][0] != 0:
r = []
for idx in range(len(d[-1])-1):
r.append(d[-1][idx+1]-d[-1][idx])
d.append(r)
for idx in range(len(d)):
if idx == 0:
d[-1].append(0)
continue
idx = -idx-1
d[idx].append(d[idx][-1]+d[idx+1][-1])
s += d[0][-1]
print(s)
s2 = 0
for d in data:
for idx in range(len(d)):
if idx == 0:
d[-1].insert(0, 0)
continue
idx = -idx-1
d[idx].insert(0, d[idx][0]-d[idx+1][0])
s2 += d[0][0]
print(s2)
|