n = int(input())
houses = list(map(int, input().split()))
wires = 0
indexes = {}
for i, plaque in enumerate(houses):
if plaque in indexes:
distance = i - indexes[plaque]
wires += distance
else:
indexes[plaque] = i
print(wires)