import sys from collections import defaultdict l1 = [] l2 = defaultdict(int) for l in sys.stdin: l = [int(x) for x in l.split()] l1.append(l[0]) l2[l[1]] += 1 s = 0 for i in range(len(l1)): s += l1[i] * l2[l1[i]] print(s)