n = int(input())
inp = list(map(int, input().split()))
wire_cost = 0
seen = [0] * n
again = [0] * n
for i in range(2*n):
num = inp[i]-1
wire_cost += sum(seen)
if seen[num] == 0:
seen[num] = 1
elif seen[num] == 1 and again[num] == 0:
again[num] = 1
print(wire_cost)