Allen is hosting a formal dinner party. $2n$ people come to the event in $n$ pairs (couples). After a night of fun, Allen wants to line everyone up for a final picture. The $2n$ people line up, but Allen doesn't like the ordering. Allen prefers if each pair occupies adjacent positions in the line, as this makes the picture more aesthetic.

Help Allen find the minimum number of swaps of adjacent positions he must perform to make it so that each couple occupies adjacent positions in the line.


-----Input-----

The first line contains a single integer $n$ ($1 \le n \le 100$), the number of pairs of people.

The second line contains $2n$ integers $a_1, a_2, \dots, a_{2n}$. For each $i$ with $1 \le i \le n$, $i$ appears exactly twice. If $a_j = a_k = i$, that means that the $j$-th and $k$-th people in the line form a couple.


-----Output-----

Output a single integer, representing the minimum number of adjacent swaps needed to line the people up so that each pair occupies adjacent positions.


-----Examples-----
Input
4
1 1 2 3 3 2 4 4

Output
2

Input
3
1 1 2 2 3 3

Output
0

Input
3
3 1 2 3 1 2

Output
3



-----Note-----

In the first sample case, we can transform $1 1 2 3 3 2 4 4 \rightarrow 1 1 2 3 2 3 4 4 \rightarrow 1 1 2 2 3 3 4 4$ in two steps. Note that the sequence $1 1 2 3 3 2 4 4 \rightarrow 1 1 3 2 3 2 4 4 \rightarrow 1 1 3 3 2 2 4 4$ also works in the same number of steps.

The second sample case already satisfies the constraints; therefore we need $0$ swaps.

Difficulty: competition

Starter code:

Solutions:
n = int(input())

xs = [int(x) for x in input().split()]

seen = {}

res = 0

while xs:
    j = xs.index(xs[0], 1)
    res += j - 1
    xs = xs[1:j] + xs[j+1:]

print(res)


n = int(input())
t = list(map(int, input().split()))

sw = 0

while t != []:
	pr = 1 + t[1:].index(t[0])
	#print(pr)
	sw += pr-1
	#print(t[1:pr], t[pr+1:])
	t = t[1:pr] + t[pr+1:]
	#print(t)

print(sw)



import sys
#sys.stdin=open("data.txt")
input=sys.stdin.readline

n=int(input())

c=list(map(int,input().split()))
ans=0

for i in range(n):
    # match the first person
    f=c.pop(0)
    g=c.index(f)
    c.pop(g)
    ans+=g

print(ans)

n = int(input())
l = [-1] * n
r = [-1] * n
a = list(map(int, input().split()))
for i in range(2 * n):
    x = a[i] - 1
    if l[x] == -1: l[x] = i
    r[x] = i
ans = 0
for i in range(n):
    for j in range(n):
        if l[i] < l[j] < r[j] < r[i]: ans += 2
for i in range(n):
    ans += r[i] - l[i] - 1
print(ans // 2)

import sys

n = int(input())
n *= 2
a = list(map (int, input().split()))
res = 0
for i in range (0, n, 2):
  if a[i] != a[i+1]:
    t = a[i]
    for j in range (i+1, n):
      if a[j] == t:
        for k in range (j, i + 1, -1):
          a[k], a[k-1] = a[k-1], a[k]
          res += 1
        break
   
#print (a)    
print (res)

#!/usr/bin/env python3

def main():
    n = int(input())
    a = list(map(int, input().split()))
    r = 0
    while a:
        c = a[0]
        del a[0]
        for i in range(len(a)):
            if c == a[i]:
                break
        del a[i]
        r += i
    print(r)

def __starting_point():
    main()

__starting_point()


import sys
import math
import os.path
import random
from queue import deque

sys.setrecursionlimit(10**9)

n, = map(int, input().split())
a = deque(list(map(int, input().split())))

s = 0

for _ in range(n):
	x = a.popleft()
	ix = a.index(x)
	s += ix
	a.remove(x)

print(s)

n = int(input())
line = input().split(" ")
for i in range(len(line)):
    line[i] = int(line[i])

ans = 0
while len(line) != 0:
    if line[0] == line[1]:
        line.pop(0)
        line.pop(0)
    else:
        first = line.pop(0)
        idx = line.index(first)
        ans += idx
        line.pop(idx)

print(ans)


n = 2 * int(input())
a = [int(i) for i in input().split()]
ans = 0
for i in range(1, len(a), 2):
    j = i
    while a[j] != a[i - 1]:
        j += 1
    while j != i:
        ans += 1
        a[j - 1], a[j] = a[j], a[j - 1]
        j -= 1
print(ans)
    


n=int(input())
a=list(map(int,input().split()))
ans=0
while len(a)>0:
    if a[0]==a[1]:
        a=a[2:]
        continue
    p=0
    for i in range(1,len(a)):
        if a[i]==a[0]:
            p=i
            break
    a=a[1:p]+a[p+1:]
    ans+=p-1
print(ans)

n = int(input())
l = [-1] * n
r = [-1] * n
a = list(map(int, input().split()))
for i in range(2 * n):
    x = a[i] - 1
    if l[x] == -1: l[x] = i
    r[x] = i
ans = 0
for i in range(n):
    for j in range(n):
        if l[i] < l[j] < r[j] < r[i]: ans += 2
for i in range(n):
    ans += r[i] - l[i] - 1
print(ans // 2)

input()
a=input().split()
ans=0
while len(a)>0:
  at=a[1:].index(a[0])+1
  ans+=at-1
  a=a[1:at]+a[at+1:]
print(ans)

n=int(input())
l=list(map(int,input().split(" ")))
a,c=0,0
while (l):
    a=l[0]
    l.remove(a)
    c+=l.index(a)
    l.remove(a)
print(c)

input()
a=input().split()
cnt=0
while len(a)>0:
  k=a[1:].index(a[0])+1
  cnt+=k-1
  a=a[1:k]+a[k+1:]
print(cnt)

# your code goes here

n = input()
n = int(n)
a = [int(i) for i in input().split()]
#print(a)
d = []
l = []
n = 2*n
d = {i:-1 for i in a}
#print(d)
#print(a)

point = 0
count = 0
for i in range(0,n):
    l.append(a[i])
    if(d[a[i]] == -1):
       # print(str(a[i]) + ' not mapped earlier')
        d[a[i]] = 0
    elif(d[a[i]] == 0):
        d[a[i]] = 1
        j = l.index(a[i])
        l.pop()
        #print(l)
        l.insert(j+1,a[i])
        #print(str(a[i]) + str(l))
        count = count + (i-j-1)
        if(j == point):
            point = point+2
        
print(count)    
            
    #print(i)    



n = int(input())
a = [*[int(x) - 1 for x in input().split()]]
"""count = [1] * n
real_position = [[] for i in range(n)]
position = [0] * (2 * n)
for i in range(2*n):
	position[i] = count[a[i]]
	count[a[i]] = -1
	real_position[a[i]].append(i)

#print(position)
sum = [i for i in position]
for i in range(1, 2*n):
	sum[i] += sum[i - 1]
	

ans1 = 0
for i in range(n):
	ans1 += (sum[real_position[i][1] - 1] - sum[real_position[i][0]])

#ans = -(ans // 2)
#print(ans)
ans = 0
for i in range(n):
	ans += (real_position[i][1] - real_position[i][0] - 1)

print(ans - ans1)
"""
ans = 0
f = [True] * n
for i in range(2 * n - 1):
	if f[a[i]]:
		j = i + 1
		while a[j] != a[i]:
			if f[a[j]]:
				ans += 1
			j += 1
		f[a[i]] = False

print(ans)


n=int(input())
li=[*map(int,input().split())]
count=0
while len(li)>0:
	a=li[0]
	li.remove(a)
	count+=li.index(a)
	li.remove(a)
print(count)

j = int(input()) * 2
l = list(map(int, input().split()))
for i in range(0, j, 2):
    if l[i] != l[i + 1]:
        break
for j in range(j, 1, -2):
    if l[j - 2] != l[j - 1]:
        break
l, res = l[i:j], 0
while l:
    i = l.index(l.pop())
    res += len(l) - i - 1
    del l[i]
print(res)

input()
a = list(input().split())
ans = 0
while len(a) > 0:
    b = a[1:].index(a[0]) + 1
    ans += b - 1
    a = a[1:b] + a[b + 1:]
print(ans)


_ = int(input())
ns = list(map(int, input().split()))
seen = [False for _ in range(len(ns)//2 + 1)]
count = 0
index = 0
while index != len(ns):
    e = ns[index]
    if seen[e]:
        while ns[index-1] != e:
            ns[index], ns[index-1] = ns[index-1], ns[index]
            seen[ns[index]] = False
            count += 1
            index -= 1
            #print(ns)
    seen[e] = True
    index += 1
print(count)


n=int(input())
n=n*2
x=[int(i) for i in input().split()] 
swap=0   
while 0 < n:
    temp=x[1:].index(x[0])
    swap=swap+temp
    x.remove(x[0])
    x.remove(x[temp])
    n=n-2
print(swap)    


n = int(input())
a = list(map(int, input().split()))
sol=0
for i in range(2*n):
    for j in range(i+1, 2*n):
        if a[i]==a[j]:
            for k in range(j, i+1, -1):
                a[j], a[j-1] = a[j-1], a[j]
                j-=1
                sol+=1
            break
print(sol)


n = int(input())
a = input().split()

for i in range (0, n+n):
	a[i] = int(a[i])
	
ans = 0

for i in range (0, 2*n-1, 2):
	x = a[i]
	if a[i] == a[i+1]:
		continue
	idx = a.index(a[i], i+1)
	ans += idx-i-1
	del a[idx]
	a.insert(i+1, a[i])
	
print(ans)



input()

a=list(map(int,input().split()))

cnt=0

while a:

 i=a.index(a.pop(0))

 cnt+=i

 a.pop(i)

print(cnt)



# Made By Mostafa_Khaled