Manao works on a sports TV. He's spent much time watching the football games of some country. After a while he began to notice different patterns. For example, each team has two sets of uniforms: home uniform and guest uniform. When a team plays a game at home, the players put on the home uniform. When a team plays as a guest on somebody else's stadium, the players put on the guest uniform. The only exception to that rule is: when the home uniform color of the host team matches the guests' uniform, the host team puts on its guest uniform as well. For each team the color of the home and guest uniform is different.

There are n teams taking part in the national championship. The championship consists of n·(n - 1) games: each team invites each other team to its stadium. At this point Manao wondered: how many times during the championship is a host team going to put on the guest uniform? Note that the order of the games does not affect this number.

You know the colors of the home and guest uniform for each team. For simplicity, the colors are numbered by integers in such a way that no two distinct colors have the same number. Help Manao find the answer to his question.


-----Input-----

The first line contains an integer n (2 ≤ n ≤ 30). Each of the following n lines contains a pair of distinct space-separated integers h_{i}, a_{i} (1 ≤ h_{i}, a_{i} ≤ 100) — the colors of the i-th team's home and guest uniforms, respectively.


-----Output-----

In a single line print the number of games where the host team is going to play in the guest uniform.


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

Output
1

Input
4
100 42
42 100
5 42
100 5

Output
5

Input
2
1 2
1 2

Output
0



-----Note-----

In the first test case the championship consists of 6 games. The only game with the event in question is the game between teams 2 and 1 on the stadium of team 2.

In the second test sample the host team will have to wear guest uniform in the games between teams: 1 and 2, 2 and 1, 2 and 3, 3 and 4, 4 and 2 (the host team is written first).

Difficulty: interview

Starter code:

Solutions:
n = int( input().split()[0] )
answer = 0
h = []
a = []
for i in range( 0, n ):
	team = input().split()
	h.append( int( team[0] ) )
	a.append( int( team[1] ) )
for i in range( 0, n ):
	for j in range( 0, n ):
		if i == j:
			continue
		if h[i] == a[j]:
			answer += 1
print( answer )


n = int(input())

count = 0

home = []
visiting = []

for i in range(n):
    h, v = map(int,input().split())
    home.append(h)
    visiting.append(v)


for l in home:
    for k in visiting:
        if l == k:
            count += 1
print(count)

import sys
inp = sys.stdin
n = int(inp.readline())
H = []
A = []
for i in range(n):
  h,a = inp.readline().split()
  H.append(h)
  A.append(a)
ans = 0  
for i in range(n):
  for j in range(n):    
    if i != j and H[i] == A[j]:
      ans += 1  
print(ans)  

n=int(input())

Home=[]
Away=[]

for i in range(n):
    a,b=input().split()
    Home.append(a)
    Away.append(b)
ans=0
for i in range(n):
    ans+=Away.count(Home[i])
    if(Away[i]==Home[i]):
        ans-=1

print(ans)


n = int(input())
a, b = [0] * n, [0] * n

for i in range(n):
    a[i], b[i] = list(map(int, input().split()))
s = 0
for j in a:
    s += b.count(j)
print(s)


import sys
import math

def games():
    datain = []
    shirts = 0
    homeshirts = []
    awayshirts = []
    
    #Taking input
    teams = int(input())
    for i in range(teams):
        datain.append(input().split())
        
    #Creating homeshirt list
    for i in range(teams):
        homeshirts.append(datain[i][0])

    #Creating awayshirt list
    for i in range(teams):
        awayshirts.append(datain[i][1])

    #Finding pairs
    for i in homeshirts:
        shirts += awayshirts.count(i)

    print(shirts)

games()


n = int(input())
a = [0 for i in range(n)]
b = [0 for i in range(n)]
for i in range(n):
    a[i],b[i] = list(map(int, input().split()))

cnt = 0
for i in range(n):
    for j in range(n):
        if a[i] == b[j]: cnt += 1
print(cnt)



n = int(input())
C_K = 101
hct = [0] * C_K
gct = [0] * C_K
for i in range(n):
	hc,gc = [int(x) for x in input().split(' ')]
	hct[hc] += 1
	gct[gc] += 1
sum = 0
for i in range(C_K):
	sum += hct[i] * gct[i]
print(sum)



n = int(input())
hlists, alists = list(), list()
for i in range(n):
    h, a = input().split(' ')
    hlists.append(h)
    alists.append(a)
print(sum(alists.count(e) for e in hlists))

c=n=int(input())
l=[]
while c:
    a=input().split(" ")
    a=[int(i) for i in a]
    l.append((a[0],a[1]))
    c-=1
count=0
h=0
while h<n:
    g=h+1
    while g<n:
        if l[h][0]==l[g][1]:
            count+=1
        if l[h][1]==l[g][0]:
            count+=1
        g+=1
    h+=1
print(count)

n = int(input())
a = []
k = 0
for i in range(0,n):
    a.append(list(map(int,input().split())))
for i in range(0,n):
    for j in range(0,n):
        if(i!=j):
            if(a[i][0] == a[j][1]):
                k += 1
print(k)

n=int(input())

home=[]
guest=[]
switch=0

for i in range(0,n):
    uniform=str(input())
    guest.append(int(uniform[uniform.index(' ')+1:]))
    home.append(int(uniform[:uniform.index(' ')]))

for i in range(0,n):
    for j in range(0,n):
        if i!=j:
            if home[i]==guest[j]:
                switch+=1

print(switch)


n = int(input())
home = []
visit = []

for i in range(0, n):
    h, v = [int(string) for string in input().split()]
    home.append(h)
    visit.append(v)
res = 0
for hh in home:
    res += visit.count(hh)
print(res)

n = int(input())
h = []
a = []
changes = 0
for i in range(n):
    x, y = map(int, input().split())
    h.append(x)
    a.append(y)
    
for i in h:
    changes += a.count(i)
    
print(changes)

c1 = {}
c2 = {}
count = 0
n = int(input())
for i in range(n):
    a,b=input().split(' ')
    if a in c1:
        c1[a] += 1
    else:
        c1[a] = 1
    if b in c2:
        c2[b] += 1
    else:
        c2[b] = 1
for i in c2:
    if i in c1:
        count += c1[i]*c2[i]
print(count)


n = int(input())
teams = []
for i in range(n):
    h, a = list(map(int, input().split()))
    teams.append([h, a])
ans = 0
for i in teams:
    for j in teams:
        if i[0] == j[1]:
            ans += 1
print(ans)


def count_guest_uniform_on_host_team(n_teams: int, home_colours: list, guest_colours: list) -> int:
    result = 0

    for i in range(n_teams):
        result += guest_colours.count(home_colours[i])

    return result

n = int(input())
h = [None] * n
a = [None] * n

for i in range(n):
    h[i], a[i] = map(int, input().split())

print(count_guest_uniform_on_host_team(n, h, a))

n = int(input())

colors = []

teams = [x for x in range(n)]

res = 0

for i in range(n):
    colors.append(tuple(map(int, input().split())))


def calc(t, s):
    nonlocal colors
    res = 0
    if len(t) == 1:
        return 0
    for i in range(len(t)):
        if colors[t[0]][s] == colors[t[i]][1-s]:
            res += 1
    return res + calc(t[1:], s)

print(calc(teams, 1) + calc(teams, 0))


n = int(input())
tshirt = []
for i in range(n):
    x = list(map(int, input().split()))
    tshirt.append(x)

count = 0

for y in range(n):
    for z in range(n):
        if tshirt[y][0] == tshirt[z][1]:
            count += 1
print(count)

n = int(input())
a = []
t = 0
for i in range(n):
    a.append(input().split())
for i in a:
    for j in a:
        if i[0] == j[1]:
            t += 1

print(t)


n = int(input())
countItems = 0

team_jersey = []
for x in range(n):
	team = input().split()
	team_jersey.append(int(team[0]))
	team_jersey.append(int(team[1]))

home = [team_jersey[x] for x in range(len(team_jersey)) if x % 2 == 0]
away = [team_jersey[x] for x in range(len(team_jersey)) if x % 2 != 0]

for x, y in enumerate(home):
	countItems += away.count(y)


print(countItems)




n = int(input())
countItems = 0

home = []
away = []

for x in range(n):
	team = input().split()
	home.append(int(team[0]))
	away.append(int(team[1]))

for x, y in enumerate(home):
	countItems += away.count(y)

print(countItems)





n = int(input())
a, b = [0]*n, [0]*n
for i in range(n):
    a[i], b[i] = map(int, input().split())
ans = 0
for ai in a:
    ans += b.count(ai)
print(ans)

sa=input()
sa2=0
homes=[]
aways=[]
for x in range(int(sa)):
    tt=input().split(' ')
    homes.append(int(tt[0]))
    aways.append(int(tt[1]))
for element in homes:
    for element2 in aways:
        if element==element2:
            sa2+=1

print(sa2)


a=int(input())
c=[]
d=[]
while a>0:
 b=input().split()
 c.append(b[0])
 d.append(b[1])
 a-=1
e=0
for i in c:
 for j in d:
  if i==j:e+=1
print(e)