#input = open("sample1.in") input = open("input") nums = [[int(x) for x in line.split()] for line in input] # part 1 a = [x[0] for x in nums] b = [x[1] for x in nums] a.sort() b.sort() distance = [abs(x-y) for x,y in zip(a,b)] print(sum(distance)) # part 2 from collections import Counter c = Counter(b) scores = [x*c[x] for x in a] print(sum(scores))