n = int(input())
inp = list(map(int, input().split()))
wire_cost = 0
add = 0
seen = [0] * n
again = [0] * n

for i in range(2*n):
    num = inp[i]-1
    wire_cost += add
    if seen[num] == 0 and again[num] == 0:
        seen[num] = 1
        add += 1
    elif seen[num] == 1 and again[num] == 0:
        again[num] = 1
        seen[num] = 0
        add -= 1

print(wire_cost)