blob: 1abc9d18a4160d92279a1277fa6229bbb081f25f (
plain)
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
33
34
35
36
|
import json
import sys
from functools import cmp_to_key
lines = [json.loads(s) for s in sys.stdin.readlines() if s.strip()]
def cmp(a, b):
def tolist(v):
return v if type(v) == list else [v]
i = 0
while True:
if len(a) <= i and len(b) <= i: return 0
if len(a) <= i: return -1
if len(b) <= i: return 1
x = a[i]
y = b[i]
if type(x) == int and type(y) == int:
if x < y: return -1
if x > y: return 1
else:
r = cmp(tolist(x), tolist(y))
if r != 0: return r
i += 1
partOne = 0
for i in range(0, len(lines), 2):
a = lines[i]
b = lines[i+1]
if cmp(a,b) != 1:
partOne += i//2+1
print(partOne)
divs = [ [[2]], [[6]] ]
lines += divs
lines = sorted(lines, key=cmp_to_key(cmp))
print((lines.index(divs[0]) + 1) * (lines.index(divs[1]) + 1))
|