n = int(input())
inp = list(map(int, input().split()))
rev_inp = inp[::-1]
sum = 0

for i in range(1,n+1):
    ind1 = inp.index(i)
    ind2 = inp.index(i)
    sum += (2 * n - ind2 - 1) - ind1

print(sum)