2022-12-13 18:35:29 +00:00
|
|
|
import json
|
2022-12-13 05:23:29 +00:00
|
|
|
|
|
|
|
data = []
|
|
|
|
for chunk in open("input").read().split("\n\n"):
|
2022-12-13 18:35:29 +00:00
|
|
|
data.append([json.loads(x) for x in chunk.splitlines(False)])
|
2022-12-13 05:23:29 +00:00
|
|
|
|
2022-12-13 18:39:36 +00:00
|
|
|
def cmp(a, b):
|
2022-12-13 05:23:29 +00:00
|
|
|
if type(a) == int and type(b) == int:
|
2022-12-13 18:39:36 +00:00
|
|
|
return (a > b) - (a < b)
|
2022-12-13 05:23:29 +00:00
|
|
|
if type(a) == list and type(b) == int:
|
|
|
|
b = [b]
|
|
|
|
elif type(a) == int and type(b) == list:
|
|
|
|
a = [a]
|
|
|
|
|
|
|
|
for x, y in zip(a,b):
|
2022-12-13 18:39:36 +00:00
|
|
|
r = cmp(x,y)
|
|
|
|
if r != 0:
|
|
|
|
return r
|
|
|
|
return cmp(len(a),len(b))
|
2022-12-13 05:23:29 +00:00
|
|
|
|
|
|
|
#print(data)
|
|
|
|
|
|
|
|
t = 0
|
|
|
|
for i,(a,b) in enumerate(data):
|
|
|
|
#print("<" if less(a,b) else ">=")
|
2022-12-13 18:39:36 +00:00
|
|
|
if cmp(a,b) < 0:
|
2022-12-13 05:23:29 +00:00
|
|
|
t += i + 1
|
|
|
|
print(t)
|
|
|
|
|
|
|
|
|
|
|
|
import functools
|
|
|
|
|
|
|
|
big = [e for x in data for e in x]
|
|
|
|
big.append([[2]])
|
|
|
|
big.append([[6]])
|
|
|
|
big.sort(key=functools.cmp_to_key(cmp))
|
|
|
|
|
|
|
|
i1 = big.index([[2]]) + 1
|
|
|
|
i2 = big.index([[6]]) + 1
|
|
|
|
|
|
|
|
print(i1*i2)
|