from sys import stdin from collections import Counter left, right = zip(*((int(a), int(b)) for a, b in map(str.split, stdin))) counter = Counter(right) print(sum(counter[n]*n for n in left))