-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path9.py
37 lines (34 loc) · 1022 Bytes
/
9.py
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
37
from collections import defaultdict
f = open("9.in")
is_lesser_than = defaultdict(list)
is_greater_than = defaultdict(list)
docs = []
sum = 0
for line in f.readlines():
if "|" in line:
a,b = list(map(int, line.split("|")))
is_lesser_than[a].append(b)
is_greater_than[b].append(a)
else:
docs.append(list(map(int, line.split(","))))
print(docs)
for doc in docs:
good_doc = True
for page in doc:
lesser = is_lesser_than[page]
greater = is_greater_than[page]
good_lesser = True
for item in lesser:
if item in doc:
if doc.index(item) < doc.index(page):
good_lesser = False
good_greater = True
for item in greater:
if item in doc:
if doc.index(item) > doc.index(page):
good_greater = False
if not (good_greater and good_lesser):
good_doc = False
if good_doc:
sum += doc[int((len(doc)-1)/2)]
print(sum)