n = int(input())
houses = map(int, input().split())
houselist = [0] * n
value = 0
magic = 0
for h in houses:
value += magic
if houselist[h - 1] == 0:
magic += 1
houselist[h - 1] = 1
elif houselist[h - 1] == 1:
magic -= 1
value += magic
print(value)