example = """ 3 4 4 3 2 5 1 3 3 9 3 3 """ parsed = [[],[]] for x in open('input.txt', 'r').readlines(): # for x in example.splitlines(): if x: a = [y for y in x.split(" ") if y] parsed[0].append(a[0]) parsed[1].append(a[1]) parsed[0] = sorted(parsed[0]) parsed[1] = sorted(parsed[1]) parsed[0] = [int(x) for x in parsed[0]] parsed[1] = [int(x) for x in parsed[1]] asd = [] for x in parsed[0]: cnt = parsed[1].count(x) asd.append(x*cnt) num = sum(asd) print(num)