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) 
            b = b + m 
         
        j -= 1
        
print(b)