blob: f5cbc0d99cc4a4ca9e65b71da539ead6e283f3ad (
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
|
from collections import Counter
input = "data/1_2024.txt"
data = open(input).read().strip()
lines = data.split("\n")
left, right, rc = [], [], Counter()
for i in lines:
l, r = i.split()
l, r = int(l), int(r)
left.append(l)
right.append(r)
rc[r] += 1
p1 = 0
left, right = sorted(left), sorted(right)
for l, r in zip(left, right):
p1 += abs(r - l)
print(p1)
p2 = 0
for l in left:
p2 += l * rc.get(l, 0)
print(p2)
|