2.py (242B) [raw]
1 import sys 2 from collections import defaultdict 3 4 l1 = [] 5 l2 = defaultdict(int) 6 7 for l in sys.stdin: 8 l = [int(x) for x in l.split()] 9 l1.append(l[0]) 10 l2[l[1]] += 1 11 12 s = 0 13 for i in range(len(l1)): 14 s += l1[i] * l2[l1[i]] 15 16 print(s)