n = int(input())
l = list(map(int, input().split()))
j = len(l) - 1
s = 0
ll = []
b = 0
for i in range(n):
    j = len(l) - 1
    for s in range(n):
        if l[i] == l[j]:
            m = abs(j - i) 
            ll.append(m) 
         
        j -= 1
        



print(sum(ll))