28 lines
627 B
Python
28 lines
627 B
Python
|
def counts(nums: list[int]) -> dict[int, int]:
|
||
|
ret = {}
|
||
|
for n in nums:
|
||
|
if n in ret:
|
||
|
ret[n] += 1
|
||
|
else:
|
||
|
ret[n] = 1
|
||
|
return ret
|
||
|
|
||
|
|
||
|
if __name__ == '__main__':
|
||
|
with open('1.input') as file:
|
||
|
left, right = [], []
|
||
|
for line in file:
|
||
|
l, r = line.split()
|
||
|
l, r = int(l), int(r)
|
||
|
left.append(l)
|
||
|
right.append(r)
|
||
|
# how many times does each number apear in each list
|
||
|
right = counts(right)
|
||
|
score = 0
|
||
|
for n in left:
|
||
|
if n not in right: continue
|
||
|
score += n * right[n]
|
||
|
print(score)
|
||
|
|
||
|
|
||
|
|