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: EASY

Solutions:
n = int(input())
arr = [tuple(map(int, input().split())) for i in range(n)]
ans = 0
for i in range(n):
	for j in range(n):
		if arr[i] == arr[j]:
			continue
		if arr[i][0] == arr[j][1]:
			ans += 1
print(ans)


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


a = int(input())
k = []
for _ in range(a):
	l = list(map(int, input().split(' ')))
	k.append(l)
count = 0
for i in range(a):
	for j in range(a):
		if i == j:
			continue
		elif k[i][0] == k[j][1]:
			count += 1
print(count)


n = int(input())
brr = [None] * n
count = 0
for i in range(n):
	brr[i] = list(map(int, input().split()))
for i in range(n):
	for j in range(n):
		if i != j:
			if brr[i][0] == brr[j][1]:
				count += 1
print(count)


n = int(input())
(a, b) = zip(*[input().split() for _ in ' ' * n])
print(sum((a.count(x) for x in b)))


(hh, aa) = ([], [])
for i in range(int(input())):
	(h, a) = map(int, input().split())
	hh.append(h)
	aa.append(a)
c = 0
for h in hh:
	for a in aa:
		if h == a:
			c += 1
print(c)


teams = int(input())
h = {}
g = {}
for i in range(teams):
	(x, y) = [int(x) for x in input().split()]
	if h.get(x) == None:
		h[x] = 1
	else:
		h[x] += 1
	if g.get(y) == None:
		g[y] = 1
	else:
		g[y] += 1
c = 0
for i in h:
	try:
		c += g[i] * h[i]
	except KeyError:
		pass
print(c)


n = int(input())
lst = list()
while n > 0:
	l = input()
	l = l.strip().split(' ')
	l[0] = int(l[0])
	l[1] = int(l[1])
	lst.append(l)
	n = n - 1
count = 0
for i in range(len(lst)):
	for j in range(len(lst)):
		if lst[i][0] == lst[j][1]:
			count = count + 1
print(count)


n = int(input())
lst = []
index_one = []
index_two = []
guest = 0
for i in range(n):
	a = list(map(int, input().split()))
	lst.append(a[0])
	lst.append(a[1])
index_one = lst[0::2]
index_two = lst[1::2]
for i in range(n):
	guest += index_two.count(index_one[i])
print(guest)


n = int(input())
li = []
for i in range(n):
	li.append([int(x) for x in input().split()])
c = 0
for i in range(n - 1):
	for j in range(i + 1, n):
		if li[i][0] == li[j][1]:
			c = c + 1
		if li[i][1] == li[j][0]:
			c = c + 1
print(c)


def game(n, array):
	c = 0
	for i in range(n):
		for j in range(n):
			if array[i][0] == array[j][1]:
				c += 1
	print(c)
n = input()
array = []
for i in range(int(n)):
	a = [int(x) for x in input().split()]
	array += [a]
game(int(n), array)


n = int(input())
count = 0
x = []
y = []
for i in range(0, n):
	(a, b) = input().split()
	x.append(a)
	y.append(b)
for i in range(0, n):
	for j in range(0, n):
		if x[i] == y[j]:
			count += 1
print(count)


from sys import stdin, stdout
n = int(stdin.readline().strip())
home_colors = []
guest_colors = []
for i in range(n):
	colors = stdin.readline().strip().split()
	home_colors.append(colors[0])
	guest_colors.append(colors[1])
count = 0
for i in guest_colors:
	count += home_colors.count(i)
stdout.write(str(count))


n = int(input())
hosts = []
guests = []
for i in range(n):
	line = [int(s) for s in input().split(' ')]
	hosts.append(line[0])
	guests.append(line[1])
count = 0
for host in hosts:
	count += guests.count(host)
print(count)


(lst, lst1) = ([], [])
for _ in range(int(input())):
	(a, b) = map(int, input().split())
	lst.append(a)
	lst1.append(b)
s = 0
for i in range(len(lst1)):
	s += lst1.count(lst[i])
print(s)


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


s = int(input())
l = []
for i in range(s):
	(a, b) = input().split()
	l.append([a, b])
count = 0
for i in range(s):
	for j in range(s):
		if i != j:
			if l[i][0] == l[j][1]:
				count = count + 1
print(count)


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


g = 0
n = int(input())
l = list()
for i in range(n):
	s = input()
	s = s.split()
	l.append(s)
for (i, j) in l:
	for (p, q) in l:
		if i == q:
			g += 1
print(g)


n = int(input())
h = []
g = []
k = 0
while n > 0:
	hg = input().split()
	hg = list(map(int, hg))
	h.append(hg[0])
	g.append(hg[1])
	n = n - 1
for i in h:
	for j in g:
		if i == j:
			k = k + 1
print(k)


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


z = int(input())
l1 = []
l2 = []
while z:
	f = input().split(' ')
	l1.append(f[0])
	l2.append(f[1])
	z -= 1
count = 0
for i in l1:
	count = count + l2.count(i)
print(count)


n = int(input())
k = []
for x in range(n):
	k += input().split()
l = 0
for a in k[1::2]:
	l += k[::2].count(a)
print(l)


n = int(input())
l = [[int(x) for x in input().split()] for _ in range(n)]
A = 0
for i in range(n):
	for j in range(n):
		if j == i:
			continue
		if l[i][1] == l[j][0]:
			A += 1
print(A)


(matrix, count) = ([[i for i in input().split()] for _ in range(int(input()))], 0)
for i in range(len(matrix)):
	for j in range(i + 1, len(matrix)):
		if matrix[i][0] == matrix[j][1]:
			count += 1
		if matrix[i][1] == matrix[j][0]:
			count += 1
print(count)


n = int(input())
ans = 0
a = [[0] * 2 for i in range(n)]
for i in range(n):
	(a[i][0], a[i][1]) = [int(x) for x in input().split()]
for i in range(n):
	for j in range(n):
		if i == j:
			continue
		if a[i][0] == a[j][1]:
			ans += 1
print(int(ans))


n = int(input())
uniform = []
for i in range(n):
	string = str(input())
	tmp = string.split()
	uniform.append(tmp)
arr = []
for i in range(n):
	for j in range(n):
		tmp = []
		if j != i:
			tmp.append(uniform[i][0])
			tmp.append(uniform[j][1])
		arr.append(tmp)
count = 0
for i in range(len(arr)):
	try:
		if arr[i][0] == arr[i][1]:
			count += 1
	except:
		pass
print(count)


n = int(input())
l = []
count = 0
for i in range(n):
	s = input()
	lst = s.split(' ')
	l.append(lst)

def match(t1, t2):
	global count
	if t1[0] == t2[1]:
		count = count + 1
	if t2[0] == t1[1]:
		count = count + 1
	return count
for i in range(len(l)):
	for j in range(i + 1, len(l)):
		match(l[i], l[j])
print(count)


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


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


n = int(input())
lst = [input() for i in range(n)]
l = []
index = 0
home = []
guest = []
count = 0
for i in lst:
	for j in i.split():
		l.append(j)
for i in range(len(l)):
	if index % 2 == 0:
		home.append(l[index])
	else:
		guest.append(l[index])
	index += 1
for i in home:
	count += guest.count(i)
print(count)


num = int(input())
l1 = []
l2 = []
sum1 = 0
for i in range(num):
	(x, y) = input().split()
	l1.append(x)
	l2.append(y)
for dress in l1:
	if dress in l2:
		sum1 += l2.count(dress)
print(sum1)


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


import sys
import math
n = int(input())
a = []
for i in range(n):
	b = [int(x) for x in input().split()]
	a.append(b)
ans = 0
for i in range(n):
	for j in range(n):
		if i != j:
			if a[i][0] == a[j][1]:
				ans += 1
print(ans)


n = int(input())
array1 = []
array2 = []
for i in range(n):
	entr = list(map(int, input().split()))
	array1.append(entr[0])
	array2.append(entr[1])
cont = 0
for i in range(n):
	for j in range(n):
		if array1[i] == array2[j]:
			cont += 1
print(cont)


def main():
	s = int(input())
	data = []
	for i in range(s):
		data.append([int(v) for v in input().split()])
	c = 0
	for i in range(s):
		for j in range(s):
			if i == j:
				continue
			if data[i][0] == data[j][1]:
				c += 1
			if data[i][1] == data[j][0]:
				c += 1
	print(c // 2)
main()


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


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


n = int(input())
(home, gust) = ([], [])
for i in range(n):
	(x, y) = map(int, input().split())
	home.append(x)
	gust.append(y)
l = 0
for i in range(n):
	j = 0
	while j < n:
		if home[i] == gust[j] and i != j:
			l = l + 1
		j = j + 1
print(l)


a = int(input())
liste = []
for i in range(a):
	b = input()
	b = b.split(' ')
	liste.append(b)
resultat = 0
for i in range(a):
	for j in range(a):
		if j != i:
			if liste[i][0] == liste[j][1]:
				resultat += 1
print(resultat)


n = int(input())
d = {}
arr = []
for _ in range(n):
	(x, y) = input().split()
	(x, y) = (int(x), int(y))
	arr.append(x)
	if y in d:
		d[y] += 1
	else:
		d[y] = 1
ans = 0
for x in arr:
	if x in d:
		ans += d[x]
print(ans)


n = int(input())
inpL = []
ans = 0
for z in range(n):
	z = [int(x) for x in input().split()]
	inpL.append(z)
for i in inpL:
	for j in inpL:
		if i[0] == j[1]:
			ans += 1
print(ans)


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


n = int(input())
teams = list()
for k in range(n):
	teams.append(list(map(int, input().split())))

def must_change(host_team, guest_team):
	return host_team[0] == guest_team[1]

def count_uniform_changes(teams):
	result = 0
	for k in range(n):
		for i in range(n):
			if i == k:
				continue
			result += 1 if must_change(teams[k], teams[i]) else 0
	return result
print(count_uniform_changes(teams))


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


n = int(input())
team = []
for i in range(n):
	(h, g) = map(int, input().split())
	team.append([h, g])
c = 0
for row in team:
	home = row[0]
	for guest in team:
		if guest != row and home == guest[1]:
			c += 1
print(c)


n = int(input())
lst = []
count = 0
for i in range(n):
	lst.append(input().split())
for i in range(0, len(lst)):
	lst[i] = [int(x) for x in lst[i]]
for i in range(0, len(lst)):
	for x in range(0, len(lst)):
		if lst[i][0] == lst[x][1]:
			count += 1
print(count)


def main():
	n = int(input())
	times = [tuple([int(x) for x in input().split()]) for _ in range(n)]
	print(solve(times, n))

def solve(times, n):
	count = 0
	for i in range(n):
		for j in range(n):
			if times[i][0] == times[j][1]:
				count += 1
	return count
main()


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


m = 0
(x, y) = ([], [])
for i in range(int(input())):
	t = input().split()
	x.append(t[0])
	y.append(t[1])
for i in x:
	m += y.count(i)
print(m)


uniforms = []
for _ in range(int(input())):
	uniforms.append([int(i) for i in input().split()])
total = 0
for i in range(len(uniforms)):
	for j in range(len(uniforms)):
		if i == j:
			continue
		if uniforms[i][1] == uniforms[j][0]:
			total += 1
print(total)


n = int(input())
l = []
s = 0
for i in range(n):
	l.append(input().split())
for j in range(n):
	for k in range(n):
		if l[j][1] == l[k][0]:
			s += 1
print(s)


n = int(input())
home = []
guest = []
while n > 0:
	[h, g] = [int(a) for a in input().split(' ')]
	home = home + [h]
	guest = guest + [g]
	n -= 1
count = 0
shift = 0
while count < len(home):
	i = home[count]
	k = 0
	while k < len(guest):
		y = guest[k]
		if i == y and count != k:
			shift = shift + 1
		k += 1
	count += 1
print(shift)


l1 = []
l2 = []
for _ in range(int(input())):
	(a, b) = map(int, input().split())
	l1.append(a)
	l2.append(b)
c = 0
for i in range(len(l1)):
	s = l2.count(l1[i])
	c = c + s
print(c)


d = []
n = int(input())
for i in range(n):
	c = list(map(int, input().split()))
	d.append(c)
s = 0
for x in range(n):
	a = d[x][0]
	for y in range(n):
		if a == d[y][1]:
			s += 1
print(s)


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


n = int(input())
cnt = 0
l = []
for i in range(n):
	t = list(map(int, input().split()))
	l.append(t)
for i in range(1, n + 1):
	for j in range(1, n + 1):
		if l[i - 1][0] == l[j - 1][1]:
			cnt = cnt + 1
print(cnt)


class TaskA(object):

	def __init__(self):
		self.get_data()
		self.solve()
		self.print_ans()
	pass

	def get_data(self):
		self.n = int(input())
		self.a = list()
		for _ in range(self.n):
			t = tuple(map(int, input().split()))
			self.a.append(t)
		pass

	def solve(self):
		self.ans = 0
		for i in range(self.n - 1):
			for j in range(i + 1, self.n):
				if self.a[i][0] == self.a[j][1]:
					self.ans += 1
				if self.a[j][0] == self.a[i][1]:
					self.ans += 1
		pass

	def print_ans(self):
		print(self.ans)
		pass

def main():
	TaskA()
	pass
main()


n = int(input())
m1 = {}
m2 = {}
for i in range(n):
	(a, b) = list(map(int, input().split()))
	if a in m1.keys():
		m1[a] += 1
	else:
		m1[a] = 1
	if b in m2.keys():
		m2[b] += 1
	else:
		m2[b] = 1
ans = 0
for temp in m1.keys():
	if temp in m2.keys():
		ans += m1[temp] * m2[temp]
print(ans)


(h, g) = ([], [])
for _ in range(int(input())):
	(home, guest) = map(int, input().split())
	h.append(home)
	g.append(guest)
c = 0
for i in range(len(h)):
	(home, guest) = (h[i], g[i])
	c += h[i + 1:].count(guest)
	c += g[i + 1:].count(home)
print(c)


all_left = []
all_right = []
for inputs in range(int(input())):
	(left, right) = map(int, input().split())
	all_left.append(left)
	all_right.append(right)
counter = 0
for item in all_left:
	for another_one_xD in all_right:
		if item == another_one_xD:
			counter += 1
print(counter)


n = int(input())
a1 = []
b1 = []
r = 0
for i in range(n):
	(a, b) = map(int, input().split())
	a1.append(a)
	b1.append(b)
for i in b1:
	r = r + a1.count(i)
print(r)


n = int(input())
games = n * (n - 1)
z = []
count = 0
for i in range(n):
	z.append(list(input().split()))
for i in range(n):
	for j in range(i + 1, n):
		if z[i][1] == z[j][0]:
			count = count + 1
		if z[i][0] == z[j][1]:
			count = count + 1
print(count)


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


x = int(input())
y = []
for i in range(x):
	cv = list(map(int, input().split()))
	y.append(cv)
ans = 0
for i in range(x):
	for j in range(x):
		if y[i][0] == y[j][1]:
			ans += 1
		else:
			continue
print(ans)


n = int(input())
u = []
g = 0
for x in range(0, n):
	u.extend([int(y) for y in input().split()])

def uniform(x, y):
	if u[2 * x] == u[2 * y + 1]:
		return 1
	return 0
for x in range(0, n):
	for y in range(0, n):
		if x == y:
			continue
		g += uniform(x, y)
print(g)


n = int(input())
a = []
count = 0
for i in range(n):
	tmp = []
	s = input().split()
	for j in range(2):
		tmp.append(s[j])
	a.append(tmp)
for i in range(n):
	for j in range(i):
		if a[i][0] == a[j][1]:
			count += 1
	for j in range(i + 1, n):
		if a[i][0] == a[j][1]:
			count += 1
print(count)


import itertools
n = int(input())
ha = [list(map(int, input().split())) for _ in range(n)]
h = []
a = []
for hai in ha:
	h.append(hai[0])
	a.append(hai[1])
cnt = 0
for (i, j) in itertools.product(h, a):
	if i == j:
		cnt += 1
print(cnt)


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


(s, a) = (0, [input().split() for _ in range(int(input()))])
for i in a:
	for j in a:
		if i[0] == j[1]:
			s += 1
print(s)


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


n = int(input())
c = []
d = []
k = 0
for i in range(n):
	(a, b) = [int(m) for m in input().split()]
	c.append(a)
	d.append(b)
for i in range(n):
	k += d.count(c[i])
print(k)


s1 = list()
d = dict()
c = 0
for _ in range(int(input())):
	s = list(map(int, input().split()))
	s1.append(s[0])
	try:
		if d[s[1]]:
			d[s[1]] += 1
	except:
		d[s[1]] = 1
for i in s1:
	try:
		if d[i]:
			c += d[i]
	except:
		pass
print(c)


n = int(input())
a = []
for _ in range(n):
	b = list(map(int, input().rstrip().split()))
	a.append(b)
c = 0
for _ in range(n):
	i = 0
	while i < n:
		if i == _:
			i += 1
		if i < n:
			if a[_][0] == a[i][1]:
				c += 1
		i += 1
print(c)


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


n = int(input())
x = []
for _ in range(n):
	x.append(input().split())
cnt = 0
for i in range(n):
	for j in range(n):
		if i == j:
			continue
		if x[i][0] == x[j][1]:
			cnt += 1
print(cnt)


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


n = int(input())
a = n * [0]
b = n * [0]
total = 0
for i in range(n):
	(a[i], b[i]) = [int(i) for i in input().split()]
for i in range(n):
	for j in range(n):
		if i != j:
			if a[i] == b[j]:
				total += 1
print(total)


n = int(input())
totalGames = n * (n - 1)
home = []
guest = []
for i in range(0, n):
	game = input().split()
	home.append(int(game[0]))
	guest.append(int(game[1]))
count = 0
for i in home:
	for j in guest:
		if i == j:
			count += 1
print(count)


n = int(input())
v = []
for i in range(0, n):
	(x, y) = map(int, input().split())
	v.append((x, y))
cnt = int(0)
for i in range(0, n):
	for j in range(0, n):
		if i == j:
			continue
		if v[i][0] == v[j][1]:
			cnt += 1
print(int(cnt))


k = int(input())
a = []
b = []
for i in range(k):
	(x, y) = map(int, input().split())
	(a.append(x), b.append(y))
print(sum((a.count(x) for x in b)))


from itertools import product
print(sum([c[0] == c[1] for c in product(*zip(*[input().split() for _ in range(int(input()))]))]))


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


n = int(input())
li1 = []
li2 = []
s = 0
for i in range(n):
	(a, b) = map(int, input().split())
	li1.append(a)
	li2.append(b)
for num in li1:
	ncount = li2.count(num)
	s += ncount
print(s)


n = int(input())
i = 0
a = []
b = []
ans = 0
while i < n:
	i = i + 1
	(c, d) = map(int, input().split())
	a.append(c)
	b.append(d)
for c in b:
	ans = ans + a.count(c)
print(ans)


n = int(input())
(x, count) = ([], 0)
for _ in range(n):
	x.append(list(map(int, input().split())))
for (k, val) in enumerate(x):
	for (j, val1) in enumerate(x):
		if k != j and val[0] == val1[1]:
			count += 1
print(count)


n = int(input())
h = []
a = []
count = 0
for _ in range(n):
	(x, y) = map(int, input().split())
	h.append(x)
	a.append(y)
for item in h:
	for item1 in a:
		if item == item1:
			count += 1
print(count)


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


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


n = int(input())
home = []
away = []
for i in range(n):
	(h, a) = map(int, input().split())
	home.append(h)
	away.append(a)
homeHash = dict()
awayHash = dict()
for i in home:
	homeHash[i] = 0
for i in away:
	awayHash[i] = 0
for i in home:
	homeHash[i] += 1
for i in away:
	awayHash[i] += 1
count = 0
for i in homeHash:
	if i in awayHash:
		x = homeHash[i] * awayHash[i]
		count += x
print(count)


import collections
teams = input()
teams_uni = []
for i in range(0, int(teams)):
	teams_uni.append(list(map(int, input().rstrip().split())))
host_team_guest_uniform_matches = 0
for i in range(0, len(teams_uni)):
	for j in range(0, len(teams_uni)):
		if i == j:
			continue
		if teams_uni[i][0] == teams_uni[j][1]:
			host_team_guest_uniform_matches += 1
print(host_team_guest_uniform_matches)


n = int(input())
li1 = []
li2 = []
lis = []
li3 = []
for i in range(n):
	li3 = [int(i) for i in input().split()]
	li1.append(li3[0])
	li2.append(li3[1])
c = 0
for i in li1:
	for j in li2:
		if i == j:
			c = c + 1
print(c)


def main():
	n = int(input())
	teams = []
	counter = 0
	for i in range(n):
		teams.append([int(x) for x in input().split()])
	for k in range(len(teams)):
		for j in range(len(teams)):
			if teams[k][0] == teams[j][1] and k != j:
				counter += 1
	print(counter)
main()


d = []
v = []
n = int(input())
for i in range(n):
	s = list(input().split(' '))
	d.append(s[0])
	v.append(s[1])
counter = 0
for i in range(0, len(d)):
	for j in range(0, len(d)):
		if i != j:
			if d[i] == v[j]:
				counter += 1
print(counter)


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


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


import sys
n = int(input())
a = [0 for x in range(n)]
b = [0 for x in range(n)]
for i in range(n):
	(a[i], b[i]) = map(int, input().split())
cnt = 0
for x in range(n):
	for y in range(n):
		if a[x] == b[y]:
			cnt += 1
print(cnt)


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


n = int(input())
d1 = {}
d2 = {}
for i in range(n):
	a = [int(x) for x in input().split()]
	try:
		d1[a[0]] += 1
	except:
		d1[a[0]] = 1
	try:
		d2[a[1]] += 1
	except:
		d2[a[1]] = 1
res = 0
for i in d1.keys():
	try:
		res += d1[i] * d2[i]
	except:
		pass
print(res)


def matchColors(n, arr):
	count = 0
	for i in range(n):
		for j in range(i + 1, n):
			if arr[i][0] == arr[j][1]:
				count += 1
			if arr[i][1] == arr[j][0]:
				count += 1
	return count
n = int(input())
arr = []
for i in range(n):
	arr.append(list(map(int, input().split())))
print(matchColors(n, arr))


counter = 0
q = int(input())
teams = [[int(i) for i in input().split()] for j in range(q)]
for i in range(q):
	for j in range(q):
		if teams[i][0] == teams[j][1]:
			counter += 1
print(counter)


n = int(input())
l = []
m = []
c = 0
for i in range(n):
	(x, y) = map(int, input().split())
	l.append(x)
	m.append(y)
for i in range(0, n):
	for j in range(0, n):
		if l[i] == m[j]:
			c += 1
print(c)


n = int(input())
home = []
guest = []
games = 0
for i in range(n):
	hg = input().split()
	home.append(hg[0])
	guest.append(hg[1])
for i in range(n - 1):
	for k in range(i + 1, n):
		if home[i] == guest[k] and home[k] == guest[i]:
			games += 2
		elif home[i] == guest[k] or home[k] == guest[i]:
			games += 1
print(games)


l = int(input())
home = []
guest = []
while l > 0:
	l = l - 1
	(x, y) = map(int, input().split())
	home.append(x)
	guest.append(y)
count = 0
for i in home:
	if i in guest:
		count += guest.count(i)
print(count)


team_count = int(input())
team_color = []
for i in range(team_count):
	team_color.append(list(map(int, input().split())))
ctr = 0
for i in range(team_count):
	for j in range(team_count):
		if team_color[i][0] == team_color[j][1]:
			ctr += 1
print(ctr)


n = int(input())
colors = [[int(x) for x in input().split(' ')] for _ in range(n)]
cnt = 0
for i in range(n):
	for j in range(i + 1, n):
		if colors[i][0] == colors[j][1]:
			cnt += 1
		if colors[i][1] == colors[j][0]:
			cnt += 1
print(cnt)


n = int(input())
m = [tuple(map(int, input().split())) for _ in range(n)]
connt = 1
for i in m:
	for j in m:
		if i != j:
			if i[0] == j[1]:
				connt += 1
print(connt - 1)


n = int(input())
ah = []
ai = []
count = 0
for _ in range(n):
	(h, i) = map(int, input().split())
	ah.append(h)
	ai.append(i)
for i in range(n):
	for j in range(n):
		if ah[i] == ai[j]:
			count += 1
print(count)


n = int(input())
h = []
a = []
for i in range(n):
	(p, q) = [int(i) for i in input().split()]
	h.append(p)
	a.append(q)
ncount = 0
for i in range(n):
	color = h[i]
	for j in a:
		if j == h[i]:
			ncount += 1
print(ncount)


n = int(input())
h = []
g = []
for i in range(n):
	(m, n) = map(int, input().strip().split(' '))
	h.append(m)
	g.append(n)
count = 0
for i in h:
	for j in g:
		if i == j:
			count = count + 1
print(count)


n = int(input())
homeUniforms = []
awayUniforms = []
ans = 0
for _ in range(n):
	(home, away) = list(map(int, input().split(' ')))
	homeUniforms.append(home)
	awayUniforms.append(away)
size = len(homeUniforms)
for i in range(size):
	for j in range(size):
		if i != j and homeUniforms[i] == awayUniforms[j]:
			ans += 1
print(ans)


n = int(input())
huni = []
ani = []
for a in range(n):
	ha = list(map(int, input().split()))
	huni.append(ha[0])
	ani.append(ha[1])
total = 0
for b in range(len(huni)):
	for c in range(len(huni)):
		if huni[b] == ani[c]:
			total += 1
print(total)


nStr = input()
n = int(nStr)
hList = [0] * n
aList = [0] * n
for i in range(n):
	haInp = input()
	hList[i] = int(haInp.split()[0])
	aList[i] = int(haInp.split()[1])
change = 0
for i in range(n):
	for j in range(n):
		if j == i:
			continue
		if hList[i] == aList[j]:
			change = change + 1
print(change)


def main():
	n = int(input())
	home = []
	guest = []
	answer = 0
	for i in range(n):
		temp = input()
		templist = temp.split()
		home.append(templist[0])
		guest.append(templist[1])
	for j in range(n):
		for k in range(n):
			if home[j] == guest[k]:
				answer += 1
	print(answer)
main()


class Unit:

	def __init__(self, h, g):
		self.h = h
		self.g = g
n = int(input())
l = []
count = 0
for i in range(0, n):
	s = str(input()).split()
	l.append(Unit(int(s[0]), int(s[1])))
count = 0
for i in range(0, len(l)):
	for ii in range(0, len(l)):
		if i == ii:
			continue
		if l[i].h == l[ii].g:
			count += 1
print(count)


n = int(input())
count = 0
arr = []
for i in range(n):
	arr.append([int(x) for x in input().split()])
for i in range(n):
	for j in range(n):
		if i != j:
			if arr[i][0] == arr[j][1]:
				count += 1
print(count)


home = []
away = []
cnt = 0
for i in range(int(input())):
	(a, b) = input().split()
	home.append(a)
	away.append(b)
for j in range(len(home)):
	for k in range(len(away)):
		if home[j] == away[k] and j != k:
			cnt = cnt + 1
print(cnt)


n = int(input())
aa = []
bb = []
for i in range(n):
	(a, b) = map(int, input().split())
	aa.append(a)
	bb.append(b)
cou = 0
for i in aa:
	cou += bb.count(i)
print(cou)


n = int(input())
(a, h) = ([], [])
for i in range(n):
	(n1, n2) = input().split()
	h.append(int(n1))
	a.append(int(n2))
r = 0
for i in range(n):
	for j in range(n):
		if i != j and h[i] == a[j]:
			r += 1
print(r)


t = int(input())
team_jersy = []
for _ in range(t):
	arr = list(map(int, input().split()))
	h = arr[0]
	a = arr[1]
	team_jersy.append((h, a))
	count = 0
	for i in range(len(team_jersy)):
		for j in range(len(team_jersy)):
			if i == j:
				pass
			if team_jersy[i][0] == team_jersy[j][1]:
				count += 1
print(count)


n = int(input())
s = []
l = []
c = 0
for i in range(n):
	(a, b) = map(int, input().split())
	l.append(a)
	s.append(b)
for i in range(len(l)):
	for j in range(len(s)):
		if l[i] == s[j]:
			c += 1
print(c)


n = int(input())
li1 = []
li2 = []
for i in range(0, n):
	(a, b) = input().split()
	a = int(a)
	b = int(b)
	li1 = li1 + [a]
	li2 = li2 + [b]
cnt = 0
for i in li1:
	if i in li2:
		cnt = cnt + li2.count(i)
print(cnt)


n = int(input())
h_c = []
g_c = []
for _ in range(n):
	(h, g) = map(int, input().split())
	h_c.append(h)
	g_c.append(g)
ans = 0
for i in range(n):
	for j in range(n):
		if i != j and h_c[i] == g_c[j]:
			ans += 1
print(ans)


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


lis1 = []
lis2 = []
count = 0
for _ in range(int(input())):
	(a, b) = map(int, input().split())
	lis1.append(a)
	lis2.append(b)
for i in lis1:
	count += lis2.count(i)
print(count)


n = int(input())
a = []
for i in range(0, n):
	b = [int(x) for x in input().split()]
	a += [b]
br = 0
for i in range(0, n):
	for j in range(0, n):
		if i != j:
			if a[i][0] == a[j][1]:
				br += 1
print(br)


n = int(input())
a = [None] * n
b = [None] * n
for i in range(n):
	(a[i], b[i]) = map(int, input().split())
res = 0
for i in range(n):
	for j in range(i + 1, n):
		if b[j] == a[i]:
			res += 1
		if a[j] == b[i]:
			res += 1
print(res)


n = int(input())
teams = []
answ = 0
while n != 0:
	a = input().split()
	teams.append([a[0], a[1]])
	n -= 1
for (i, x) in enumerate(teams):
	teams.pop(i)
	for (z, y) in enumerate(teams):
		if y[0] == x[1]:
			answ += 1
	teams.insert(i, x)
print(answ)


n = int(input())
a = []
b = []
for z in range(n):
	(num1, num2) = map(int, input().split())
	a.append(num1)
	b.append(num2)
count = 0
for i in range(len(a)):
	for j in range(len(b)):
		if a[i] == b[j]:
			count += 1
print(count)


plays = {}
for pi in range(int(input())):
	(li, vi) = map(int, input().split())
	if li in plays:
		plays[li][0] += 1
	else:
		plays[li] = [1, 0]
	if vi in plays:
		plays[vi][1] += 1
	else:
		plays[vi] = [0, 1]
resp = 0
for values in plays.values():
	resp += values[0] * values[1]
print(resp)


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


import itertools as it
n = int(input())
comForms = []
for _ in range(n):
	comForms.append(input().split())
change = 0
for (i, j) in it.product(range(n), repeat=2):
	if comForms[i][1] == comForms[j][0]:
		change += 1
print(change)


t = int(input())
n = t
H = []
A = []
while n:
	(h, a) = map(int, input().split())
	H.append(h)
	A.append(a)
	n -= 1
cn = 0
for i in range(t):
	for j in range(t):
		if H[i] == A[j]:
			cn += 1
print(cn)


home = []
guest = []
s = 0
t = int(input())
for _ in range(t):
	(x, y) = map(int, input().split())
	home.append(x)
	guest.append(y)
for i in home:
	s += guest.count(i)
print(s)


x = []
y = []
c = 0
for i in range(int(input())):
	(a, b) = map(int, input().split())
	for j in range(len(y)):
		if y[j] == a:
			c += 1
	for j in range(len(x)):
		if x[j] == b:
			c += 1
	x.append(a)
	y.append(b)
print(c)


n = int(input())
h = []
g = []
for i in range(0, n):
	(a, b) = map(int, input().split())
	h.append(a)
	g.append(b)
count = 0
for i in range(0, n):
	for j in range(0, n):
		if i != j and h[i] == g[j]:
			count = count + 1
print(count)


n = int(input())
a = []
b = []
for i in range(0, n):
	(x, y) = input().split()
	a.append(x)
	b.append(y)
c = 0
for j in range(0, len(a)):
	for k in range(0, len(b)):
		if j == k:
			continue
		elif a[j] == b[k]:
			c = c + 1
print(c)


n = int(input())
l = []
for i in range(n):
	l.append(tuple((int(i) for i in input().split())))
g = 0
for i in range(n):
	for j in range(n):
		if i != j and l[i][0] == l[j][1]:
			g += 1
print(g)


teams = int(input())
matrix = []
for i in range(0, teams):
	temp = [int(x) for x in input().split()]
	matrix.append(temp)
count = 0
for i in range(0, teams):
	for j in range(0, teams):
		if i != j:
			if matrix[i][0] == matrix[j][1]:
				count += 1
print(count)


t = int(input())
l = []
for _ in range(t):
	temp = list(map(int, input().split()))
	l.append(temp)
k = 1
mm = 0
count = 0
for i in range(t - 1):
	for j in range(i + 1, t):
		if l[i][k] == l[j][0]:
			count += 1
		if l[i][mm] == l[j][1]:
			count += 1
print(count)


teams = int(input())
(uni, total) = ([], 0)
for i in range(teams):
	uni.append(input().split())
for team in uni:
	for g in range(teams):
		if team[0] == uni[g][1]:
			total += 1
print(total)


n = int(input())
home = []
guest = []
for i in range(n):
	(h, g) = map(int, input().split())
	home.append(h)
	guest.append(g)
k = 0
for h in home:
	k = k + guest.count(h)
print(k)


n = int(input())
home = []
geust = []
ans = 0
for x in range(n):
	f = list(map(int, input().split()))
	home.append(f[0])
	geust.append(f[1])
for i in range(n):
	for j in range(n):
		if home[i] == geust[j]:
			ans += 1
print(ans)


n = int(input())
i = 0
jersey = [[0] * 2 for i in range(n)]
while i < n:
	(jersey[i][0], jersey[i][1]) = map(int, input().split(' '))
	i += 1
i = count = 0
while i < n:
	j = 0
	while j < n:
		if j == i:
			pass
		elif jersey[i][0] == jersey[j][1]:
			count += 1
		j += 1
	i += 1
print(count)


n = int(input())
l_ = []
for i in range(n):
	l_ += [input().split()]
t = len([[x, y] for x in range(len(l_)) for y in range(len(l_)) if x != y and l_[x][0] == l_[y][1]])
print(t)


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


n = int(input())
L_h = []
L_a = []
num = 0
for i in range(n):
	(h, a) = [int(x) for x in input().split()]
	if h in L_a:
		num += L_a.count(h)
	if a in L_h:
		num += L_h.count(a)
	L_h.append(h)
	L_a.append(a)
print(num)


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


n = int(input())
hst = []
gst = []
for i in range(n):
	hg = input().strip().split(' ')
	hst.append(int(hg[0]))
	gst.append(int(hg[1]))
count = 0
for i in range(n):
	for j in range(n):
		if hst[i] == gst[j]:
			count += 1
print(count)


def uniform(lista):
	counter = 0
	for i in range(0, len(lista)):
		temp = lista[:]
		temp.remove(lista[i])
		for j in temp:
			if lista[i][0] == j[1]:
				counter += 1
	return counter
_ = int(input())
inp = []
for i in range(0, _):
	inp.append(list(map(int, input().rstrip().split())))
print(uniform(inp))


import sys
n = int(sys.stdin.readline()[:-1])
teams = []
for i in range(n):
	team = [int(ele) for ele in sys.stdin.readline()[:-1].split()]
	teams.append(team)
output = 0
for i in range(0, len(teams)):
	for j in range(0, len(teams)):
		if teams[i][0] == teams[j][1]:
			output += 1
print(output)


n = int(input())
a = []
b = []
for _ in range(n):
	(x, y) = input().split()
	a.append(x)
	b.append(y)
print((sum((b.count(x) for x in a)) + sum((a.count(x) for x in b))) // 2)


n = int(input())
hl = []
gl = []
for i in range(n):
	(h, g) = map(int, input().split())
	hl.append(h)
	gl.append(g)
c = 0
for i in hl:
	c += gl.count(i)
print(c)


h = []
g = []
for ii in range(int(input())):
	(a, b) = [int(x) for x in input().split()]
	h.append(a)
	g.append(b)
ans = 0
for i in range(len(h)):
	for j in range(len(g)):
		if i != j:
			if h[i] == g[j]:
				ans += 1
print(ans)


n = int(input())
s = [[int(i) for i in input().split()] for j in range(n)]
z = 0
for i in s:
	for j in s:
		if i[0] == j[1]:
			z += 1
print(z)


n = int(input())
h = []
a = []
for i in range(n):
	(hi, ai) = input().split()
	h.append(hi)
	a.append(ai)
count = 0
for c in h:
	for d in a:
		if c == d:
			count += 1
print(count)


n = int(input())
h = []
g = []
for i in range(n):
	(x, y) = list(map(int, input().rstrip().split()))
	h += [x]
	g += [y]
count = 0
for i in range(n):
	x = h[i]
	for j in range(n):
		if x == g[j]:
			count += 1
print(count)


n = int(input())
h = {}
a = {}
for i in range(n):
	(hi, ai) = [int(x) for x in input().split()]
	if hi in h:
		h[hi] += 1
	else:
		h[hi] = 1
	if ai in a:
		a[ai] += 1
	else:
		a[ai] = 1
ans = 0
for uniform in h:
	away = 0
	if uniform in a:
		away = a[uniform]
	ans += away * h[uniform]
print(ans)


no_of_teams = int(input())
(home_uniform, guest_uniform) = ([], [])
for i in range(no_of_teams):
	(h, g) = map(int, input().split(' '))
	home_uniform.append(h)
	guest_uniform.append(g)

def change_uniform(home, opponent):
	return opponent.count(home)
same_uniforms = [change_uniform(i, guest_uniform) for i in home_uniform]
print(sum(same_uniforms))


def getInts():
	return [int(s) for s in input().split()]

def getInt():
	return int(input())

def getStrs():
	return [s for s in input().split()]

def getStr():
	return input()

def listStr():
	return list(input())
import collections as c

def solve():
	N = getInt()
	home = c.defaultdict(int)
	away = c.defaultdict(int)
	for n in range(N):
		(A, B) = getInts()
		home[A] += 1
		away[B] += 1
	ans = 0
	for h in home:
		ans += home[h] * away[h]
	return ans
ans = solve()
print(ans)


home = []
guest = []
ncount = 0
for i in range(int(input())):
	li = [int(x) for x in input().split()]
	home.append(li[0])
	guest.append(li[1])
for x in home:
	if x in guest:
		n = 0
		for m in guest:
			if m == x:
				n += 1
		ncount += n
print(ncount)


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 = []
res = 0
for i in range(n):
	x = input().split()
	a.append(x[0])
	b.append(x[1])
for j in a:
	for k in b:
		if j == k:
			res += 1
print(res)


n = int(input())
matches = n * (n - 1)
dress = []
for i in range(n):
	(h, g) = list(map(int, input().split()))
	dress.append(h)
	dress.append(g)

def fromFirst():
	change = 0
	i = 0
	j = 0
	while j < len(dress):
		if i == j:
			j += 3
			if dress[i] == dress[j]:
				change += 1
				j += 2
			else:
				j += 2
		elif dress[i] == dress[j]:
			change += 1
			j += 2
		else:
			j += 2
	return change

def afterFirst():
	change = 0
	for i in range(2, len(dress), 2):
		if len(dress) - 1 - i == 1:
			j = 0
			j = i - 1
			if j != 0:
				while j > 0:
					if dress[i] == dress[j]:
						change += 1
						j -= 2
					else:
						j -= 2
			else:
				return change
		else:
			j = 0
			while j < len(dress):
				if j == 0:
					j += 1
					if dress[i] == dress[j]:
						change += 1
						j += 2
					else:
						j += 2
				elif dress[i] == dress[j]:
					change += 1
					j += 2
				else:
					j += 2
	return change
print(fromFirst() + afterFirst())


n = int(input())
teams = []
for _ in range(n):
	teams.append([int(i) for i in input().split()])
overlaps = 0
for i in range(n):
	home_shirt = teams[i][0]
	for j in range(n):
		if i == j:
			continue
		visitor_shirt = teams[j][1]
		if home_shirt == visitor_shirt:
			overlaps += 1
print(overlaps)


n = int(input())
home = []
guest = []
count = 0
for x in range(n):
	(h, g) = map(int, input().split())
	home.append(h)
	guest.append(g)
for x in home:
	count += guest.count(x)
print(count)


n = int(input())
l1 = []
l2 = []
cnt = 0
for i in range(n):
	(x, y) = map(int, input().split())
	l1.append(x)
	l2.append(y)
for i in range(n):
	for j in range(n):
		if l1[i] == l2[j]:
			cnt += 1
print(cnt)


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


t = int(input())
(h, g) = ([], [])
for _ in range(t):
	(n, m) = map(int, input().split())
	h.append(n)
	g.append(m)
c = 0
for i in g:
	c = c + h.count(i)
print(c)


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


n = int(input())
li = []
for i in range(0, n):
	li += list(map(int, input().split()))
count = 0
for i in range(0, len(li), 2):
	for j in range(1, len(li), 2):
		if i != j - 1 and li[i] == li[j]:
			count += 1
print(count)


n = int(input())
home = []
away = []
for _ in range(0, n):
	(a, b) = map(int, input().split())
	home.append(a)
	away.append(b)
ans = 0
for _ in home:
	ans += away.count(_)
for _ in away:
	ans += home.count(_)
print(ans // 2)


li = []
li1 = []
for i in range(int(input())):
	li2 = [int(i) for i in input().split()]
	li.append(li2[0])
	li1.append(li2[1])
c = 0
for i in li:
	c += li1.count(i)
print(c)


h = []
a = []
for _ in range(int(input())):
	(c, b) = [int(i) for i in input().split()]
	h.append(c)
	a.append(b)
cnt = 0
for i in h:
	cnt += a.count(i)
print(cnt)


n = int(input())
h = list()
a = list()
for i in range(n):
	(hi, ai) = map(int, input().split())
	h.append(hi)
	a.append(ai)
u = 0
for q in range(n):
	u = u + a.count(h[q])
print(u)


n = int(input())
a = []
count = 0
for i in range(n):
	b = []
	(k1, k2) = map(int, input().split())
	b.append(k1)
	b.append(k2)
	a.append(b)
for i in range(n):
	for j in range(n):
		f = a[i][0]
		if a[j][1] == f:
			count += 1
print(count)


t = int(input())
a = []
b = []
w = t
while t > 0:
	x = input()
	(i, j) = x.split()
	a.append(int(i))
	b.append(int(j))
	t = t - 1
j = 1
ctr = 0
k = 1
ctr1 = 0
for i in range(w):
	for j in range(i + 1, w):
		if a[i] == b[j]:
			ctr = ctr + 1
for i in range(w):
	for j in range(i + 1, w):
		if b[i] == a[j]:
			ctr1 = ctr1 + 1
print(ctr + ctr1)


n = int(input())
l = n * ['']
for i in range(n):
	a = [int(i) for i in input().split()]
	l[i] = a
t = 0
for i in range(n):
	a = l[i]
	b = a[0]
	c = a[1]
	for j in range(n):
		d = l[j][1]
		if d == b:
			t = t + 1
	for k in range(n):
		d = l[k][0]
		if c == d:
			t = t + 1
print(t // 2)


n = int(input())
m = []
for _ in range(n):
	m.append(list(map(int, input().split())))
ans = 0
for i in range(len(m)):
	r = m[i][0]
	for j in range(len(m)):
		if r == m[j][1]:
			ans += 1
print(ans)


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


n = int(input())
uniform = {}
home_uniform = []
ts = 0
while n > 0:
	n -= 1
	(h, a) = [int(j) for j in input().split()]
	while (h, ts) in uniform:
		ts += 1
	uniform[h, ts] = a
	home_uniform.append((h, ts))
cnt = 0
guest_uniform = []
for hu in home_uniform:
	for (k, v) in uniform.items():
		if k == hu:
			continue
		guest_uniform.append(v)
	for gu in guest_uniform:
		if hu[0] == gu:
			cnt += 1
	guest_uniform.clear()
print(cnt)


tymov = int(input())
tymy = []
for i in range(tymov):
	tymy.append(list(map(int, input().split())))
rovnakych = 0
for i in range(tymov - 1):
	for j in range(i + 1, tymov):
		if tymy[i][0] == tymy[j][1]:
			rovnakych += 1
		if tymy[i][1] == tymy[j][0]:
			rovnakych += 1
print(rovnakych)


n = int(input())
mas = []
for i in range(n):
	temp = [int(i) for i in input().split()]
	mas.append(temp)
count = 0
for i in range(n):
	for j in range(n):
		if mas[i][0] == mas[j][1]:
			count += 1
print(count)


n = int(input())
nog = n * (n - 1)
L = []
count = 0
for _ in range(n):
	l = [int(ele) for ele in input().split()]
	L.append(l)
for e in L:
	for i in range(0, len(L)):
		if e == L[i]:
			continue
		if e[0] == L[i][1]:
			count += 1
print(count)


n = int(input())
(l1, l2) = ([], [])
c = 0
for i in range(n):
	(a, b) = map(int, input().split())
	l1.append(a)
	l2.append(b)
for i in range(n):
	c += l2.count(l1[i])
print(c)


(home, away) = ([], [])
for i in range(int(input())):
	(a, b) = map(int, input().strip().split())
	home.append(a)
	away.append(b)
print(sum((away.count(h) for h in home)))


n = int(input())
ans = 0
al = []
bl = []
for i in range(n):
	(a, b) = [int(s) for s in input().split(' ')]
	al.append(a)
	bl.append(b)
for i in al:
	if i in bl:
		ans += bl.count(i)
print(ans)


n = int(input())
teams = []
count = 0
for i in range(n):
	test = input().split()
	teams.append(test)
for i in range(n):
	for j in range(n):
		if i != j and teams[i][1] == teams[j][0]:
			count += 1
print(count)


n = int(input())
HOMECOLOR = []
GUESTCOLOR = []
num = 0
for i in range(n):
	(a, b) = input().split()
	HOMECOLOR.append(a)
	GUESTCOLOR.append(b)
for i in range(len(HOMECOLOR)):
	for x in range(len(HOMECOLOR)):
		if HOMECOLOR[i] == GUESTCOLOR[x]:
			num += 1
print(num)


n = int(input())
l1 = []
l2 = []
for i in range(0, n):
	(x, y) = input().split()
	l1.append(x)
	l2.append(y)
l1 = list(map(int, l1))
l2 = list(map(int, l2))
c = 0
for j in range(0, n):
	for k in range(0, n):
		if l1[j] == l2[k]:
			c += 1
print(c)


n = int(input())
l1 = []
l2 = []
for i in range(n):
	a = [int(x) for x in input().split()]
	l1.append(a[0])
	l2.append(a[1])
answer = 0
for i in range(n):
	for e in range(n):
		if l1[i] == l2[e]:
			answer += 1
print(answer)


n = int(input())
a = []
b = {}
for i in range(n):
	(x, y) = map(int, input().split())
	a.append(x)
	if y in b.keys():
		b[y] += 1
	else:
		b[y] = 1
c = 0
for i in a:
	if i in b.keys():
		c += b[i]
print(c)


teams = int(input())
championship = teams * (teams - 1)
host = []
guest = []
manyTimes = 0
while teams > 0:
	(a, b) = map(int, input().split())
	host.append(a)
	guest.append(b)
	teams -= 1
i = len(host)
for h in range(0, i):
	for g in range(0, i):
		if host[h] == guest[g]:
			manyTimes += 1
print(manyTimes)


n = int(input())
a = []
b = []
k = 0
for i in range(n):
	s = input()
	a.append(int(s.split(' ')[0]))
	b.append(int(s.split(' ')[-1]))
for i in range(n):
	for j in range(n):
		if i != j:
			if a[i] == b[j]:
				k += 1
print(str(k))


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


n = int(input())
host = []
guest = []
for x in range(n):
	(h, g) = map(int, input().split(' '))
	host.append(h)
	guest.append(g)
count = 0
for a in host:
	for b in guest:
		if b == a:
			count = count + 1
print(count)


n = int(input())
y = []
d = 0
for i in range(n):
	x = list(map(int, input().split()))
	y.append(x)
for i in range(len(y)):
	for j in range(len(y)):
		if i != j and y[i][0] == y[j][1]:
			d = d + 1
print(d)


team1 = []
team2 = []
counter = 0
n = int(input())
for i in range(n):
	x = input()
	team1.append(x.split()[0])
	team2.append(x.split()[1])
for i in range(n):
	for j in range(n):
		if i == j:
			continue
		elif team1[i] == team2[j]:
			counter += 1
print(counter)


from sys import stdin
n = int(stdin.readline())
count = 0
c = []
for x in range(n):
	(a, b) = list(map(int, input().split()))
	c.append((a, b))
for i in range(n):
	for j in range(n):
		if i != j:
			if c[i][0] == c[j][1]:
				count += 1
print(count)


I = int(input())
S = []
for i in range(I):
	(A, B) = map(int, input().split())
	S.append(A)
	S.append(B)
i = 0
y = 0
while i < len(S):
	r = 1
	while r < len(S):
		if S[i] == S[r]:
			y += 1
		r += 2
	i += 2
print(y)


(h, g) = ([], [])
for _ in range(int(input())):
	x = list(map(int, input().split()))
	h.append(x[0])
	g.append(x[1])
res = 0
for c in h:
	if c in g:
		res += g.count(c)
print(res)


n = int(input())
host_uniforms = []
guest_uniforms = []
match = 0
for _ in range(n):
	(h, g) = list(map(int, input().split()))
	host_uniforms.append(h)
	guest_uniforms.append(g)
for i in host_uniforms:
	for j in guest_uniforms:
		if i == j:
			match += 1
print(match)


n = int(input(''))
l = []
for k in range(0, n):
	g = []
	(q, b) = input('').split(' ')
	h = int(q)
	a = int(b)
	g.append(h)
	g.append(a)
	l.append(g)
count = 0
for j in range(0, n):
	for t in range(0, n):
		if l[j][0] == l[t][1]:
			count = count + 1
print(count)


n = int(input())
arr = []
for i in range(n):
	arr.append([int(i) for i in input().split()])
res = 0
for i in arr:
	h = i[0]
	for j in arr:
		if h == j[1]:
			res += 1
print(res)


t = int(input())
l = []
for _ in range(t):
	l1 = list(input().split())
	l.append(l1)
s = 0
for i in range(t - 1):
	for j in range(i + 1, t):
		l2 = l[i]
		l3 = l[j]
		if l2[0] == l3[1]:
			s += 1
		if l2[1] == l3[0]:
			s += 1
print(s)


n = int(input())
x = []
y = []
out = 0
for i in range(n):
	(a, b) = [int(x) for x in input().split()]
	x.append(a)
	y.append(b)
for num in x:
	for nu in y:
		if num == nu:
			out += 1
print(out)


teams = int(input())
(home, away) = ({}, {})
result = 0
clash = 0
for team in range(teams):
	colors = input().split()
	(home_color, away_color) = (colors[0], colors[1])
	if home_color == away_color:
		clash += 1
	if home_color in home.keys():
		home[home_color] += 1
	else:
		home[home_color] = 1
	if away_color in away.keys():
		away[away_color] += 1
	else:
		away[away_color] = 1
for item in away.keys():
	if item in home.keys():
		result += away[item] * home[item] - clash * (teams - 1)
print(result)


import math
import os
import sys
import re
import itertools
import functools
import operator
n = int(input())
(A, B) = ([None] * n, [None] * n)
for i in range(n):
	(A[i], B[i]) = map(int, input().split())
res = 0
for i in range(len(A)):
	for j in range(len(B)):
		if i != j and A[i] == B[j]:
			res = res + 1
print(res)


import sys
input = sys.stdin.readline

def inp():
	return int(input())

def inlt():
	return list(map(int, input().split()))

def insr():
	s = input()
	return list(s[:len(s) - 1])

def invr():
	return map(int, input().split())
n = inp()
home = [0] * n
away = [0] * n
for i in range(n):
	a = inlt()
	home[i] = a[0]
	away[i] = a[1]
homeset = set(home)
awayset = set(away)
intersection = homeset.intersection(awayset)
games = 0
for i in intersection:
	games += home.count(i) * away.count(i)
print(games)


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)


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


t = int(input())
d = []
f = []
c = 0
for i in range(0, t):
	(n, m) = list(map(int, input().split()))
	d.append(n)
	f.append(m)
for j in d:
	if j in f:
		c += f.count(j)
print(c)


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


n = int(input())
l1 = []
l2 = []
for _ in range(n):
	(a, b) = map(int, input().split())
	l1.append(a)
	l2.append(b)
d = {}
for i in range(n):
	if l2[i] in d:
		d[l2[i]] += 1
	else:
		d[l2[i]] = 1
s = 0
for i in range(n):
	if l1[i] in d:
		s += d[l1[i]]
print(s)


n = int(input())
hl = []
al = []
for i in range(n):
	(h, a) = map(int, input().split())
	hl.append(h)
	al.append(a)
r = 0
for t in hl:
	r += al.count(t)
print(r)


n = int(input())
t = 0
X = []
Y = []
for i in range(n):
	(x, y) = [int(x) for x in input().split()]
	if y in X:
		t += X.count(y)
	if x in Y:
		t += Y.count(x)
	X.append(x)
	Y.append(y)
print(t)


n = int(input())
h = []
g = []
for i in range(n):
	(s, t) = input().split(' ')
	h.append(s)
	g.append(t)
s = 0
for x in h:
	for y in g:
		if x == y:
			s += 1
print(s)


n = int(input())
a = []
b = []
for i in range(n):
	(x, y) = map(int, input().split())
	a.append(x)
	b.append(y)
ans = 0
for i in range(n):
	for j in range(i + 1, n):
		if i != j and a[i] == b[j]:
			ans += 1
		if i != j and b[i] == a[j]:
			ans += 1
print(ans)


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


s = int(input())
matches = [(x, y) for x in range(1, s + 1) for y in range(1, s + 1) if x != y]
teams_color = []
for ind in range(s):
	teams_color.append(list(map(int, input().split())))
counter = 0
for match in matches:
	if teams_color[match[0] - 1][0] == teams_color[match[1] - 1][1]:
		counter += 1
print(counter)


n = int(input().strip())
dic = {}
for _ in range(n):
	(a, b) = [int(__) for __ in input().strip().split()]
	dic[_ + 1] = (a, b)
ans = 0
for i in range(1, n):
	for j in range(i + 1, n + 1):
		if dic[i][0] == dic[j][1]:
			ans += 1
		if dic[i][1] == dic[j][0]:
			ans += 1
print(ans)


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


def getcount(g, h):
	res = 0
	for x in g:
		if x in h:
			res += h.count(x)
	return res
n = int(input())
(g, h) = ([], [])
for x in range(n):
	(a, b) = tuple(map(int, input().split()))
	g.append(a)
	h.append(b)
print(getcount(g, h))


n = int(input())
home = list()
away = list()
c = 0
for i in range(n):
	(a, b) = input().split(' ')
	home.append(a)
	away.append(b)
for i in range(n):
	for j in range(n):
		if home[i] == away[j]:
			c += 1
print(c)


n = int(input())
list = []
for i in range(n):
	(x, y) = [int(j) for j in input().split()]
	list.append(x)
	list.append(y)
k = 0
for i in range(0, 2 * n, 2):
	for j in range(1, 2 * n + 1, 2):
		if list[i] == list[j]:
			k += 1
print(k)


number = int(input())
teams = [input().split() for i in range(number)]
counter = 0
i = 0
z = 0
for j in range(number * number):
	if j % number == 0 and j != 0:
		i += 1
		z = 0
	if teams[i][0] == teams[z][1] and z != i:
		counter += 1
	z += 1
print(counter)


hostColor = []
guestColor = []
for case in range(int(input())):
	[host, guest] = [int(x) for x in input().split()]
	hostColor.append(host)
	guestColor.append(guest)
times = 0
for host in hostColor:
	for guest in guestColor:
		if host == guest:
			times += 1
print(times)


a = int(input())
h = []
g = []
k = int(0)
for x in range(a):
	(b, c) = map(int, input().split())
	h.append(b)
	g.append(c)
for i in range(a):
	for j in range(a):
		if h[i] == g[j]:
			k = k + 1
print(k)


n = int(input())
homes = list()
aways = list()
for i in range(0, n):
	(h, a) = map(int, input().split())
	homes.append(h)
	aways.append(a)
games = 0
for colour in homes:
	games += aways.count(colour)
print(games)


def main():
	t = int(input())
	n = t
	li = []
	cnt = 0
	while t > 0:
		li1 = list(map(int, input().split()))
		li.append(li1)
		t -= 1
	for i in range(n):
		for j in range(n):
			if i == j:
				pass
			elif li[j][1] == li[i][0]:
				cnt += 1
	print(cnt)
main()


value = int(input())
num = list()
for i in range(value):
	values = input()
	values = values.split()
	for i in values:
		num.append(int(i))
count = 0
for i in range(0, value * 2, 2):
	for j in range(1, value * 2, 2):
		if num[i] == num[j]:
			count += 1
print(count)


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


n = int(input())
c = 0
h = [0] * n
g = [0] * n
for i in range(n):
	(h[i], g[i]) = map(int, input().split())
for i in range(n):
	for j in range(n):
		if h[i] == g[j]:
			c += 1
print(c)


li = []

def appendToList(n):
	for i in range(n):
		li.append([])
count = 0
n = int(input())
appendToList(n)
for i in range(n):
	li[i] = input().split()
for i in range(n - 1):
	for j in range(i + 1, n):
		if li[i][0] == li[j][1]:
			count += 1
		if li[i][1] == li[j][0]:
			count += 1
print(count)


n = int(input())
arr1 = []
arr2 = []
for i in range(n):
	ab = input().split()
	arr1.append(int(ab[0]))
	arr2.append(int(ab[1]))
cnt = 0
for i in range(n):
	cnt += arr2.count(arr1[i])
print(cnt)


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


Teams = list()
number = input()
team_A = ' '
team_B = ' '
(A, B, X, Y) = (' ', ' ', ' ', ' ')
counter = 0
for x in range(1, int(number) + 1):
	(team_A, team_B) = input().split(' ')
	Teams.append(team_A)
	Teams.append(team_B)
for i in range(0, len(Teams), 2):
	j = i + 2
	A = Teams[i]
	B = Teams[i + 1]
	if j < len(Teams):
		for b in range(j, len(Teams), 2):
			X = Teams[b]
			Y = Teams[b + 1]
			if A == Y:
				counter += 1
			if X == B:
				counter += 1
print(counter)


p = input
n = int(p())
c = 0
(a, b) = zip(*[p().split() for i in ' ' * n])
for i in a:
	c += b.count(i)
print(c)


a = int(input())
b = []
c = []
for i in range(a):
	(g, d) = map(int, input().split())
	b.append(g)
	c.append(d)
s = 0
for i in c:
	if b.count(i):
		s += b.count(i)
print(s)


from sys import stdin
from collections import Counter
N = int(stdin.readline())
home = []
away = []
total = 0
for team in range(N):
	(x, y) = map(int, stdin.readline().split())
	home.append(x)
	away.append(y)
count1 = Counter(home)
count2 = Counter(away)
for i in count1:
	total += count1[i] * count2.get(i, 0)
print(total)


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


n = int(input())
z = []
b = 0
for i in range(n):
	z += [tuple(map(int, input().split()))]
for i in z:
	for j in z:
		if i != z and i[0] == j[1]:
			b += 1
print(b)


n = int(input())
l = []
for i in range(n):
	l.append(input().split(' '))
re = 0
for i in range(n):
	for j in range(i + 1, n):
		if l[i][0] == l[j][-1]:
			re += 1
		if l[i][-1] == l[j][0]:
			re += 1
print(re)


n = int(input())
l = []
while n:
	h = list(map(int, input().split()))
	l.append(h)
	n = n - 1
count = 0
for i in l:
	for j in l:
		if i[0] == j[1] and i != j:
			count = count + 1
print(count)


n = int(input().strip())
arr = {}
for a0 in range(1, n + 1):
	(h, g) = map(int, input().strip().split(' '))
	arr[a0] = (h, g)
count = 0
for i in range(1, n + 1):
	for j in range(1, n + 1):
		if i == j:
			pass
		elif arr[i][0] == arr[j][1]:
			count = count + 1
print(count)


n = int(input())
host = []
guest = []
for i in range(n):
	(h, g) = map(int, input().split())
	host.append(h)
	guest.append(g)
output = 0
for h in host:
	x = guest.count(h)
	output += x
print(output)


n = int(input())
home = {}
guest = {}
count = 0
for _ in range(n):
	(h, a) = map(int, input().split())
	if h in home:
		home[h] += 1
	else:
		home[h] = 1
	if a in guest:
		guest[a] += 1
	else:
		guest[a] = 1
for (k, v) in guest.items():
	if k in home:
		count += v * home[k]
print(count)


n = int(input())
uniforms = []
for _ in range(n):
	uniforms.append([int(x) for x in input().split()])
res = 0
for (index1, t1) in enumerate(uniforms):
	for (index2, t2) in enumerate(uniforms):
		if index1 == index2:
			continue
		if t1[0] == t2[1]:
			res += 1
print(res)


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


f = int(input())
team1 = []
team2 = []
while f > 0:
	Jrc = input().split()
	team1.append(Jrc[0])
	team2.append(Jrc[1])
	f -= 1
e = 0
for i in team1:
	for j in team2:
		if i == j:
			e += 1
print(e)


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


def Games(n, s):
	count = 0
	for i in range(n):
		for j in range(n):
			if s[i][1] == s[j][0]:
				count = count + 1
	return count
x = int(input())
li = []
for i in range(x):
	s = [int(n) for n in input().split()]
	li.append(s)
print(Games(x, li))


s = int(input())
totalArr = []
firstDic = {}
secondDic = {}
firstUnique = []
secondUnique = []
while s > 0:
	l = input().split()
	initArr = [int(x) for x in l]
	(one, two) = initArr
	if firstDic.get(one, 0) == 0:
		firstDic[one] = 1
		firstUnique.append(one)
	else:
		firstDic[one] += 1
	if secondDic.get(two, 0) == 0:
		secondDic[two] = 1
		secondUnique.append(two)
	else:
		secondDic[two] += 1
	s -= 1
count = 0
for i in firstUnique:
	count += firstDic.get(i, 0) * secondDic.get(i, 0)
print(count)


numberOfTeams = int(input())
homeUniforms = []
guestUniforms = []
for i in range(numberOfTeams):
	team = [int(j) for j in input().split()]
	homeUniforms.append(team[0])
	guestUniforms.append(team[1])
changeUniform = 0
for host in homeUniforms:
	for guest in guestUniforms:
		if host == guest:
			changeUniform += 1
print(changeUniform)


n = int(input())
d = [list(map(int, input().split())) for i in range(n)]
print(sum((d[i][0] == d[j][1] and i != j for i in range(n) for j in range(n))))


from itertools import combinations
n = int(input())
l = []
for i in range(n):
	(a, b) = map(int, input().split())
	l.append((a, b))
c = 0
for x in combinations(l, 2):
	if x[0][0] == x[1][1]:
		c += 1
	if x[0][1] == x[1][0]:
		c += 1
print(c)


n = int(input())
host = []
guest = []
t = 0
for i in range(n):
	(host_color, guest_color) = map(int, input().split())
	host.append(host_color)
	guest.append(guest_color)
for color in host:
	if color in guest:
		k = guest.count(color)
		t += k
print(t)


teams = int(input())
jers = []
for i in range(teams):
	jers.append(tuple(input().split()))
count = 0
for i in range(len(jers) - 1):
	t = jers[i]
	for j in range(i + 1, len(jers)):
		t2 = jers[j]
		if t[0] == t2[1]:
			count += 1
		if t[1] == t2[0]:
			count += 1
print(count)


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


from collections import defaultdict
d1 = defaultdict(int)
d2 = defaultdict(int)
for _ in range(int(input())):
	(n1, n2) = map(int, input().split())
	d1[n1] += 1
	d2[n2] += 1
print(sum((d1[n] * d2[n] for n in d2)))


x = int(input())
h = []
a = []
count = 0
for i in range(x):
	(h1, a1) = input().split()
	h.append(int(h1))
	a.append(int(a1))
for i in range(len(h)):
	count += (a[:i] + a[i + 1:]).count(h[i])
print(count)


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


list = []
guestcolor = []
count = 0
step = 0
for i in range(0, int(input())):
	list.append([int(i) for i in input().split()])
for i in list:
	guestcolor.append(i[1])
for i in list:
	checkguest = guestcolor[:]
	del checkguest[step]
	step += 1
	for a in checkguest:
		if a == i[0]:
			count += 1
print(count)


n = int(input())
myLiHome = []
myLiAway = []
for team in range(n):
	(a, b) = map(int, input().split())
	myLiHome.append(a)
	myLiAway.append(b)
conflicts = 0
for i in range(len(myLiHome)):
	if myLiHome[i] in myLiAway:
		conflicts += myLiAway.count(myLiHome[i])
print(conflicts)


n = int(input())
(h, a) = zip(*[(hi, ai) for (hi, ai) in [map(int, input().split()) for i in ' ' * n]])
print(sum([a.count(hi) for hi in h]))


n = int(input())
c = 0
d = []
e = []
for i in range(0, n):
	(a, b) = [int(x) for x in input().split()]
	d.append(a)
	e.append(b)
for i in range(0, len(d)):
	for j in range(0, len(e)):
		if d[i] == e[j]:
			c = c + 1
print(c)


n = int(input())
commands = []
for i in range(n):
	(home, guest) = map(int, input().split())
	commands.append([home, guest])
count = 0
for i in range(n):
	for j in range(i + 1, n):
		if commands[i][0] == commands[j][1]:
			count += 1
		if commands[i][1] == commands[j][0]:
			count += 1
print(count)


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


x = int(input())
m = [[]]
l = [[int(i) for i in input().split(' ')] for j in range(x)]
h = []
g = []
for i in l:
	h.append(i[0])
	g.append(i[1])
counter = 0
for i in range(len(h)):
	for j in range(len(g)):
		if i != j and h[i] == g[j]:
			counter += 1
print(counter)


n = int(input())
unih = []
unig = []
count = 0
for i in range(n):
	p = input()
	z = p.split(' ')
	unih.append(int(z[0]))
	unig.append(int(z[1]))
for i in range(n):
	for j in range(n):
		if unih[i] == unig[j]:
			count = count + 1
		else:
			pass
print(count)


l = []
count = 0
k = int(input())
for _ in range(k):
	l.append(input().split())
for i in range(k):
	for j in range(k):
		if l[i][0] == l[j][1]:
			count += 1
print(count)


n = int(input())
team = []
host = []
total = 0
for _ in range(n):
	(t, h) = list(map(int, input().split()))
	team.append(t)
	host.append(h)
for x in range(n):
	for y in range(n):
		if x != y and team[x] == host[y]:
			total += 1
print(total)


n = int(input())
home = []
away = []
for i in range(n):
	(o, p) = map(int, input().split())
	home.append(o)
	away.append(p)
c = 0
for i in range(n):
	for j in range(n):
		if home[i] == away[j]:
			c += 1
print(c)


n = int(input())
a = []
b = []
res = 0
for _ in range(n):
	(x, y) = map(int, input().split())
	a.append(x)
	b.append(y)
for i in a:
	for j in b:
		if i == j:
			res += 1
print(res)


n = int(input())
a = []
b = []
natija = int(0)
for i in range(0, n):
	s = input()
	s = s.split()
	a.append(int(s[0]))
	b.append(int(s[1]))
for i in range(0, n):
	if a[i] in b:
		natija = natija + b.count(a[i])
print(natija)


import operator as op
import re
import sys
from bisect import bisect, bisect_left, insort, insort_left
from collections import Counter, defaultdict, deque
from copy import deepcopy
from decimal import Decimal
from functools import reduce
from itertools import accumulate, combinations, combinations_with_replacement, groupby, permutations, product
from math import acos, asin, atan, ceil, cos, degrees, factorial, gcd, hypot, log2, pi, radians, sin, sqrt, tan
from operator import itemgetter, mul
from string import ascii_lowercase, ascii_uppercase, digits

def inp():
	return int(input())

def inlist():
	return list(map(int, input().split()))

def instr():
	s = input()
	return list(s[:len(s)])

def invr():
	return map(int, input().split())

def def_value():
	return 0
n = inp()
a = []
d = defaultdict(def_value)
for _ in range(n):
	(x, y) = invr()
	a.append(x)
	d[y] += 1
res = 0
for i in a:
	res += d[i]
print(res)


t = int(input())
total = 0
teams = []
for i in range(t):
	(h, a) = input().split()
	teams.append((h, a))
for i in teams:
	(h, a) = i
	for j in teams:
		(hh, aa) = j
		if h == aa:
			total += 1
print(total)


n = int(input())
home = [0] * n
guest = [0] * n
for i in range(n):
	(h, g) = map(int, input().split())
	home[i] = h
	guest[i] = g
ans = 0
for i in range(n):
	for j in range(n):
		if i != j:
			if guest[j] == home[i]:
				ans += 1
print(ans)


number = int(input())
arr = []
brr = []
for i in range(0, number):
	(temp1, temp2) = map(int, input().split())
	arr.append(temp1)
	brr.append(temp2)
cnt = 0
for i in range(0, number):
	for j in range(0, number):
		if i == j:
			continue
		if arr[i] == brr[j]:
			cnt = cnt + 1
print(cnt)


n = int(input())
diff = 0
homeTeams = []
awayTeams = []
for i in range(n):
	str1 = input().split(' ')
	homeTeams.append(str1[0])
	awayTeams.append(str1[1])
for i in range(len(homeTeams)):
	if homeTeams[i] in awayTeams:
		diff += awayTeams.count(homeTeams[i])
print(diff)


n = int(input())
input_list = []
for x in range(n):
	numbers = [int(i) for i in input().split()]
	input_list.append(numbers)
count = 0
flatlist = [item for sublist in input_list for item in sublist]
list1 = []
list2 = []
for x in range(len(flatlist)):
	if x % 2 == 0:
		list1.append(flatlist[x])
	else:
		list2.append(flatlist[x])
for item in list1:
	count += list2.count(item)
print(count)


t = int(input())
L = []
for i in range(0, t):
	(a, b) = map(int, input().split())
	L.append((a, b))
ans = list(zip(*L))
c = 0
for i in range(0, len(ans[0])):
	c = c + ans[1].count(ans[0][i])
print(c)


n = int(input())
home = []
guest = []
count = 0
while n > 0:
	ins = input().split()
	home.append(int(ins[0]))
	guest.append(int(ins[1]))
	n -= 1
for i in home:
	for j in guest:
		if i == j:
			count += 1
print(count)


import itertools
n = int(input())
list1 = []
count = 0
for _ in range(n):
	list1.append(list(map(int, input().split())))
for item in list(itertools.permutations(list1, 2)):
	if item[0][0] == item[1][1]:
		count += 1
print(count)


a = int(input())
home_list = []
away_list = []
output = 0
for i in range(a):
	(home, away) = [int(i) for i in input().split()]
	home_list.append(home)
	away_list.append(away)
for i in range(a):
	output += home_list.count(away_list[i])
print(output)


n = int(input())
s1 = list()
s2 = list()
t = 0
for i in range(n):
	c = input().split()
	c1 = c[0]
	c2 = c[1]
	s1.append(c1)
	s2.append(c2)
for i1 in s1:
	if i1 in s2:
		t += s2.count(i1)
print(t)


n = int(input())
l = list()
for i in range(n):
	tmp = list(input().split(' '))
	l.append(tmp)
sum = 0
for i in range(n):
	for j in range(n):
		if l[i][0] == l[j][1]:
			sum += 1
print(sum)


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 _ in a:
	ans += b.count(_)
print(ans)


n = int(input())
data = []
for i in range(n):
	x = input().split()
	data += [x]
jum = 0
for i in range(len(data) - 1):
	for j in range(i + 1, len(data)):
		if data[i][0] == data[j][1]:
			jum += 1
		if data[i][1] == data[j][0]:
			jum += 1
print(jum)


teams = int(input())
values = []
count = 0
for i in range(teams):
	values.append(list(map(int, input().split(' '))))
for i in range(teams):
	for j in range(teams):
		if values[i][1] == values[j][0]:
			count += 1
print(count)


from sys import stdin
_input = stdin.readline
(_int, _len, _range) = (int, len, range)

def solution():
	arr = []
	for i in _range(_int(_input())):
		arr.append([_int(i) for i in _input().split()])
	n = _len(arr)
	ans = 0
	for i in _range(n):
		for j in _range(n):
			if i != j and arr[i][0] == arr[j][1]:
				ans += 1
	print(ans)
solution()


n = int(input())
home = []
guest = []
res = 0
for _ in range(n):
	inp = input()
	(x, y) = [int(i) for i in inp.split(' ')]
	home.append(x)
	guest.append(y)
for i in home:
	for j in guest:
		if i == j:
			res += 1
print(res)


h = []
g = []
for t in range(int(input())):
	(a, b) = map(int, input().split())
	h.append(a)
	g.append(b)
sum = 0
for i in h:
	c = g.count(i)
	sum = sum + c
print(sum)


from itertools import product
N = int(input())
H = []
G = []
for _ in range(N):
	(h, g) = list(map(int, input().split()))
	H.append(h)
	G.append(g)
C = 0
print(len(list(filter(lambda x: x[0] == x[1], list(product(H, G))))))


n = int(input())
a = {}
b = {}
for i in range(n):
	(x, y) = map(int, input().split())
	if x in a:
		a[x] += 1
	else:
		a[x] = 1
	if y in b:
		b[y] += 1
	else:
		b[y] = 1
ans = 0
for x in a:
	if x in b:
		ans += a[x] * b[x]
print(ans)


def main():
	n = int(input())
	lst1 = []
	lst2 = []
	for i in range(0, n):
		(ele, vin) = input().split()
		lst1.append(ele)
		lst2.append(vin)
	count = 0
	for i in range(0, n):
		for j in range(0, n):
			if i != j and lst1[i] == lst2[j]:
				count += 1
	print(count)
main()


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


n = int(input())
(h, g) = ([], [])
for i in range(n):
	(x, y) = map(str, input().split())
	h.append(x)
	g.append(y)
playedInGuest = 0
for i in range(n):
	for j in g[:n] + g[n + 1:]:
		if h[i] == j:
			playedInGuest += 1
print(playedInGuest)


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


from sys import stdin, stdout
import re
import itertools
import collections
n = int(stdin.readline().rstrip())
guest = []
home = []
for _ in range(n):
	(h, g) = map(int, stdin.readline().rstrip().split())
	home.append(h)
	guest.append(g)
change = 0
for color in home:
	change += guest.count(color)
print(change)


n = int(input(''))
L = []
L1 = []
for k in range(n):
	(n, m) = map(int, input().split(' '))
	L.append(n)
	L1.append(m)
cont = 0
for k in range(len(L)):
	for j in range(len(L1)):
		if L[k] == L1[j]:
			cont += 1
print(cont)


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


n = int(input())
(a, b) = zip(*(input().split() for _ in range(n)))
y = []
for i in b:
	y.append(a.count(i))
print(sum(y))


n = int(input())
home = []
away = []
for i in range(0, n):
	(h, a) = [int(x) for x in input().split()]
	home.append(h)
	away.append(a)
answer = 0
for x in home:
	if x in away:
		answer += away.count(x)
print(answer)


n = int(input())
teams = []
for _ in range(n):
	teams.append(tuple(input().split()))
count = 0
for i in range(len(teams)):
	(h1, a1) = teams[i]
	for j in range(i + 1, len(teams)):
		(h2, a2) = teams[j]
		if h1 == a2:
			count += 1
		if h2 == a1:
			count += 1
print(count)


n = int(input())
i = 0
Col = []
Colnum = []
Col2 = []
Col2num = []
while i < n:
	i += 1
	B = [int(x) for x in input().split()]
	if B[0] not in Col:
		Col.append(B[0])
		Colnum.append(1)
	else:
		c = Col.index(B[0])
		Colnum[c] += 1
	if B[1] not in Col2:
		Col2.append(B[1])
		Col2num.append(1)
	else:
		c = Col2.index(B[1])
		Col2num[c] += 1
T = 0
for i in range(len(Col2)):
	if Col2[i] in Col:
		m = Col.index(Col2[i])
		T += Col2num[i] * Colnum[m]
print(T)


n = int(input())
home = []
guest = []
ans = 0
for _ in range(n):
	(a, b) = input().split()
	home.append(a)
	guest.append(b)
for i in range(n):
	ans += guest.count(home[i])
print(ans)


n = int(input())
arr = []
for i in range(n):
	(h, o) = [int(x) for x in input().split()]
	arr.append((h, o))

def count(forms, index=0):
	result = 0
	if index < len(forms):
		(h, o) = forms[index]
		result = count(forms, index + 1)
		for (i, f) in enumerate(forms):
			if i != index and o == f[0]:
				result += 1
	return result
print(count(arr))


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


n = int(input())
d = {}
for i in range(1, n + 1):
	(h, g) = map(int, input().split())
	d[i] = (h, g)
from itertools import permutations
l = list(permutations(d.keys(), 2))
count = 0
for i in l:
	if d[i[0]][0] == d[i[1]][1]:
		count += 1
print(count)


n = int(input())
h = []
a = []
for i in range(n):
	(H, A) = map(int, input().split())
	h.append(H)
	a.append(A)
ct = 0
for i in range(n):
	for j in range(n):
		if i == j:
			continue
		elif h[i] == a[j]:
			ct += 1
print(ct)


c = list(zip(*(map(int, input().split()) for _ in range(int(input())))))
count = 0
for x in c[0]:
	for y in c[1]:
		if x == y:
			count += 1
print(count)


n = int(input())
teams = []
for i in range(n):
	teams.append(input().split(' '))
guestsUniforms = 0
for i in range(len(teams)):
	for j in range(len(teams)):
		if i != j:
			if teams[j][1] == teams[i][0]:
				guestsUniforms += 1
print(guestsUniforms)


n = int(input())
S1 = []
S2 = []
for i in range(n):
	S = input().split()
	S1.append(S[0])
	S2.append(S[1])
k = 0
for i in range(n):
	for j in range(n):
		if S1[i] == S2[j]:
			k = k + 1
print(k)


import math
from collections import *
import sys
from functools import reduce

def get_ints():
	return map(int, input().strip().split())

def get_list():
	return list(get_ints())

def get_string():
	return list(input().strip().split())

def printxsp(*args):
	return print(*args, end='')

def printsp(*args):
	return print(*args, end=' ')
UGLYMOD = int(1000000000.0) + 7
SEXYMOD = 998244353
MAXN = int(100000.0)
n = int(input())
home = defaultdict(lambda : 0)
away = defaultdict(lambda : 0)
for i in range(n):
	(a, b) = get_ints()
	home[a] += 1
	away[b] += 1
ans = 0
for (jersey, count) in home.items():
	ans += count * away[jersey]
print(ans)


from sys import stdin
n = int(stdin.readline())
t = dict()
for i in range(n):
	t[i] = stdin.readline()[:-1].split(' ')
r = 0
for i in range(n):
	for j in range(n):
		if i != j:
			r += 1 if t[i][0] == t[j][1] else 0
print(r)


import os
import sys
from io import BytesIO, IOBase

def main():
	pass
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def binary(n):
	return bin(n).replace('0b', '')

def decimal(s):
	return int(s, 2)

def pow2(n):
	p = 0
	while n > 1:
		n //= 2
		p += 1
	return p

def isPrime(n):
	if n == 1:
		return False
	else:
		root = int(n ** 0.5)
		root += 1
		for i in range(2, root):
			if n % i == 0:
				return False
		return True
n = int(input())
h = []
g = []
for i in range(n):
	(a, b) = [int(x) for x in input().split()]
	h.append(a)
	g.append(b)
ans = 0
for i in h:
	for j in g:
		if i == j:
			ans += 1
print(ans)


n = int(input())
h = dict()
g = dict()
for i in range(n):
	(a, b) = [int(x) for x in input().split()]
	if not a in h:
		h[a] = 1
	else:
		h[a] += 1
	if not b in g:
		g[b] = 1
	else:
		g[b] += 1
ans = 0
for (k, v) in h.items():
	ans += g[k] * v if k in g else 0
print(ans)


def inputMatrix(rows):
	return [list(map(int, input().split())) for _ in range(rows)]
from collections import defaultdict
N = int(input())
d = defaultdict(int)
t = []
for _ in range(N):
	(H, G) = map(int, input().split())
	d[G] += 1
	t.append(H)
c = 0
for tt in t:
	if d[tt]:
		c += d[tt]
print(c)


n = int(input())
s = 0
A = []
for i in range(n):
	A.append(input().split())
for p in range(n):
	for q in range(p, n):
		if p != q:
			if A[p][0] == A[q][1]:
				s += 1
			if A[q][0] == A[p][1]:
				s += 1
print(s)


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


n = int(input())
lis = []
num = 0
for i in range(n):
	tmp = input().split()
	lis.append(tmp)
for j in range(n):
	for k in range(n):
		if j != k:
			if lis[j][0] == lis[k][1]:
				num += 1
print(num)


n = int(input())
list = []
list2 = []
result = 0
p = 0
for i in range(n):
	(a, b) = map(int, input().split())
	list.append(a)
	list2.append(b)
for i in range(len(list)):
	for s in range(len(list)):
		if list[s] == list2[i]:
			result += 1
print(result)


n = int(input())
home = []
away = []
for i in range(n):
	forms = [int(i) for i in input().split()]
	home.append(forms[0])
	away.append(forms[1])
n = 0
for i in home:
	n += away.count(i)
print(n)


(l, m) = ([], [])
for i in range(int(input())):
	(h, a) = map(int, input().split(' '))
	l.append(h)
	m.append(a)
c = 0
for i in l:
	x = m.count(i)
	c += x
print(c)


n = int(input())
list1 = []
count = 0
for i in range(n):
	(h, a) = map(int, input().split())
	list1.append([h, a])
for i in range(n):
	for j in range(n - i):
		if list1[i][0] == list1[j + i][1] and list1[i][1] == list1[j + i][0]:
			count += 2
		if list1[i][0] == list1[j + i][1] and list1[i][1] != list1[j + i][0] or (list1[i][0] != list1[j + i][1] and list1[i][1] == list1[j + i][0]):
			count += 1
print(count)


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


n = int(input())
home = []
guest = []
output = 0
for i in range(n):
	(homecolor, guestcolor) = input().split()
	home.append(homecolor)
	guest.append(guestcolor)
for i in range(n):
	output += guest.count(home[i])
print(output)


count = int(input())
res = 0
matches = []
for i in range(count):
	matches.append(list(map(int, input().split(' '))))
for i in range(count):
	for j in range(count):
		if matches[i][0] == matches[j][1]:
			res += 1
print(res)


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


n = int(input())

def solves(n):
	count = 0
	home = []
	guess = []
	for i in range(n):
		(h, g) = map(int, input().split())
		home.append(h)
		guess.append(g)
	for i in range(len(home)):
		for j in range(len(guess)):
			if home[i] == guess[j]:
				count += 1
	return count
print(solves(n))


n = int(input())
host = []
guest = []
counter = 0
for i in range(n):
	(a, b) = map(int, input().split())
	host.append(a)
	guest.append(b)
for i in range(n):
	for j in range(n):
		if host[i] == guest[j]:
			counter += 1
print(counter)


n = int(input())
count = 0
num = [[int(i) for i in input().split()] for i in range(n)]
for i in range(n):
	for j in range(n):
		if num[i][1] == num[j][0]:
			count += 1
print(count)


n = int(input())
hd = []
gd = []
for i in range(n):
	(h, g) = input().split()
	hd.append(int(h))
	gd.append(int(g))
c = 0
for i in range(n):
	for j in range(n):
		if hd[i] == gd[j]:
			c += 1
print(c)


N = int(input())
teams = []
ans = 0
for i in range(N):
	team = input().split()
	team_int = [int(x) for x in team]
	teams.append(team_int)
	for j in range(i - 1, -1, -1):
		if teams[j][0] == team_int[1]:
			ans = ans + 1
		if teams[j][1] == team_int[0]:
			ans = ans + 1
print(ans)


n = int(input())
h = [None] * n
g = [None] * n
for i in range(n):
	(h[i], g[i]) = map(int, input().split())
ch = 0
for hc in h:
	for gc in g:
		if hc == gc:
			ch += 1
print(ch)


def s():
	n = int(input())
	a = []
	b = []
	ans = 0
	for i in range(n):
		(tempa, tempb) = [int(x) for x in input().split(' ')]
		a.append(tempa)
		b.append(tempb)
	for x in a:
		for y in b:
			if x == y:
				ans += 1
	print(ans)
s()


x = int(input())
a = []
b = []
x1 = int(x)
while x != 0:
	y = input().split()
	a.append(y[0])
	b.append(y[1])
	x -= 1
c = 0
for i in a:
	for j in b:
		if i == j:
			c = c + 1
print(c)


n = int(input())
ans = 0
a = str('')
h = str('')
for i in range(n):
	b = [int(k) for k in input().split(' ')]
	a = a + ' ' + str(b[0])
	h = h + ' ' + str(b[1])
a = a.split(' ')
h = h.split(' ')
a = a[1:]
h = h[1:]
for i in range(len(a)):
	a[i] = int(a[i])
	h[i] = int(h[i])
for i in range(n):
	for j in range(n):
		if i != j and h[i] == a[j]:
			ans = ans + 1
print(ans)


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


n = int(input())
host_counts = {}
guest_counts = {}
for i in range(n):
	(h, g) = map(int, input().split())
	if h in host_counts:
		host_counts[h] = host_counts[h] + 1
	else:
		host_counts[h] = 1
	if g in guest_counts:
		guest_counts[g] = guest_counts[g] + 1
	else:
		guest_counts[g] = 1
result = 0
for i in range(1, 101):
	if i in host_counts and i in guest_counts:
		result = result + host_counts[i] * guest_counts[i]
print(result)


class UnitStruct:
	homeNum = 0
	outNum = 0
units = {}
num = 0
n = int(input())
for i in range(n):
	a = list(map(int, input().split()))
	if a[0] not in units:
		units[a[0]] = UnitStruct()
	units[a[0]].homeNum += 1
	if a[1] not in units:
		units[a[1]] = UnitStruct()
	units[a[1]].outNum += 1
for i in units:
	num += units[i].homeNum * units[i].outNum
print(num)


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


n = int(input().strip())
(homes, aways) = ([], [])
for i in range(n):
	(h, a) = [int(x) for x in input().split()]
	homes.append(h)
	aways.append(a)
ctr = 0
for h in homes:
	ctr += aways.count(h)
print(ctr)


def get_numlist():
	list_in = list(input().split())
	list_out = []
	for k in list_in:
		list_out += [int(k)]
	return list_out

def main():
	a = int(input())
	list_zhu = []
	list_ke = []
	out = 0
	for _ in range(a):
		list1 = get_numlist()
		list_zhu += [list1[0]]
		list_ke += [list1[1]]
	for i in list_zhu:
		out += list_ke.count(i)
	print(out)
main()


from itertools import permutations
count = 0
n = int(input())
color = []
[color.append(list(map(int, input().split()))) for i in range(n)]
perm = permutations(color, 2)
for i in list(perm):
	if i[0][0] == i[1][1]:
		count += 1
print(count)


import sys

class soccerColor:

	def __init__(self):
		self.home = []
		self.away = dict([])

	def addColor(self, h, a):
		self.home.append(h)
		if a in self.away:
			self.away[a] += 1
		else:
			self.away[a] = 1

	def calculate(self):
		count = 0
		for h in self.home:
			if h in self.away:
				count += self.away[h]
		return count

def main():
	teams = int(sys.stdin.readline().strip())
	champion = soccerColor()
	for i in range(teams):
		(h, a) = [int(x) for x in sys.stdin.readline().strip().split()]
		champion.addColor(h, a)
	print(champion.calculate())
main()


i = input
n = int(i())
cp = n
m = 0
l = []
while n:
	l.append(list(i().split()))
	n -= 1
h = [int(x) for (x, y) in l]
a = [int(y) for (x, y) in l]
for i in range(cp):
	for j in range(cp):
		m = m + 1 if h[i] == a[j] else m
print(m)


wear_guest_in_home = 0
teams = int(input())
home_color = []
guest_color = []
for _ in range(teams):
	arr = list(map(int, input().split()))
	home_color.append(arr[0])
	guest_color.append(arr[1])
for i in guest_color:
	wear_guest_in_home += home_color.count(i)
print(wear_guest_in_home)


t = int(input())
count = 0
teams = []
for i in range(t):
	teams.append(input().split())
for i in range(t):
	for j in range(t):
		if i != j:
			if teams[i][0] == teams[j][1]:
				count += 1
print(count)


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


from collections import Counter
(x, y) = (Counter(), Counter())
for i in range(int(input())):
	(a, b) = list(map(int, input().split()))
	x[a] += 1
	y[b] += 1
ans = 0
for l in dict(x).keys():
	if l in dict(y):
		ans += dict(x)[l] * dict(y)[l]
print(ans)


k = int(input())
k_own = []
k_guest = []
for _ in range(k):
	(o, g) = map(int, input().split())
	k_own.append(o)
	k_guest.append(g)
ans = 0
for i in k_own:
	ans += k_guest.count(i)
print(ans)


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


def solve(team):
	homeTeam = 0
	for home in range(0, len(team)):
		for away in range(0, len(team)):
			if home == away:
				continue
			homeJersey = team[home][0]
			awayJersey = team[away][1]
			if homeJersey == awayJersey:
				homeTeam += 1
	return homeTeam
n = int(input())
team = list()
for _ in range(0, n):
	(h, a) = map(int, input().split(' '))
	team.append((h, a))
print(solve(team))


def solve():
	n = int(input())
	num = 0
	h = [None] * n
	a = [None] * n
	for i in range(n):
		(h[i], a[i]) = map(int, input().split())
		for j in range(i):
			if h[i] == a[j]:
				num += 1
			if a[i] == h[j]:
				num += 1
	return num
print(solve())


L = []
for a in range(int(input())):
	L.append(list(map(int, input().split())))
res = 0
for i in [x[0] for x in L]:
	for j in [x[1] for x in L]:
		if i is j:
			res = res + 1
print(res)


n = int(input())
m = 0
l = []
for i in range(n):
	l.append(list(input().split()))
for i in range(n):
	for j in range(n):
		if l[i][0] == l[j][1]:
			m += 1
print(m)


n = int(input())
from collections import deque
h = deque(maxlen=n)
a = deque(maxlen=n)
(h_app, a_app) = (h.append, a.append)
for _ in range(n):
	(i, j) = map(int, input().split())
	h_app(i)
	a_app(j)
a_c = a.count
print(sum((a_c(i) for i in h)))


n = int(input())
home = []
away = []
count = 0
for i in range(n):
	temp = input()
	temp = temp.split()
	home.append(temp[0])
	away.append(temp[1])
for i in home:
	for j in away:
		if i == j:
			count += 1
print(count)


teams = int(input())
colours = []
for i in range(teams):
	colours.append(input().split(' '))
host_c = []
guest_c = []
for j in range(len(colours)):
	for k in range(2):
		if k == 0:
			host_c.append(colours[j][k])
		elif k == 1:
			guest_c.append(colours[j][k])
count = 0
for l in range(len(colours)):
	for m in range(len(colours)):
		if host_c[l] == guest_c[m]:
			count += 1
print(count)


n = int(input())
(h, g) = ([], [])
t = 0
for i in range(n):
	li = [int(e) for e in input().split()]
	h.append(li[0])
	g.append(li[1])
for i in g:
	t += h.count(i)
print(t)


n = int(input())
ht = []
gt = []
for i in range(n):
	(h, g) = list(map(int, input().split()))
	ht.append(h)
	gt.append(g)
count = 0
for i in range(n):
	for j in range(n):
		if ht[i] == gt[j] and i != j:
			count += 1
print(count)


n = int(input())
t = []
tc = []
while n:
	a = [int(k) for k in input().split()]
	t.append(a[0])
	tc.append(a[1])
	n -= 1
val = 0
for i in t:
	for j in tc:
		if i == j:
			val += 1
print(val)


n = int(input())
home = []
guest = []
while --n:
	line = input()
	(a, b) = [int(i) for i in line.split()]
	home.append(a)
	guest.append(b)
	n -= 1
cont = 0
for i in range(len(home)):
	for k in range(len(home)):
		if home[i] == guest[k]:
			cont += 1
print(cont)


n = int(input())
(list_home, list_guest) = ([], [])
count = 0
for i in range(n):
	(p, q) = map(int, input().split())
	list_home.append(p)
	list_guest.append(q)
for j in list_home:
	count += list_guest.count(j)
print(count)


def main():
	fora = []
	casa = []
	n = int(input())
	for _ in range(n):
		(c, f) = [int(x) for x in input().split()]
		fora.append(f)
		casa.append(c)
	print(solve(fora, casa, n))

def solve(fora, casa, n):
	troca = 0
	for color_c in casa:
		for color_f in fora:
			if color_c == color_f:
				troca += 1
	return troca
main()


tc = int(input())
team = []
for _ in range(tc):
	team.append(list(map(int, input().split())))
count = 0
for m in team:
	for n in team:
		if m == n:
			pass
		elif n[0] == m[1]:
			count += 1
print(count)


n = int(input())
n1 = []
n2 = []
for i in range(n):
	x = input().split()
	n1.append(x[0])
	n2.append(x[1])
c = int(0)
c1 = int(0)
for i in range(n):
	for y in range(n):
		if i > y:
			if n1[i] == n2[y]:
				c = int(c) + 1
for i in range(n):
	for y in range(n):
		if i > y:
			if n2[i] == n1[y]:
				c1 = int(c1) + 1
print(c + c1)


Home = []
Guest = []
times = 0
for i in range(int(input())):
	(H, G) = input().split()
	Home.append(H)
	Guest.append(G)
for i in Home:
	times += Guest.count(i)
print(times)


n = int(input())
f = []
s = []
res = 0
for i in range(n):
	lst = list(map(int, input().split()))
	f.append(lst[0])
	s.append(lst[1])
for i in range(n):
	for c in range(n):
		if f[i] == s[c]:
			res += 1
print(res)


def gameDresses(n, lst):
	cnt = 0
	for i in range(0, n):
		for j in range(0, n):
			if i != j and lst[i][0] == lst[j][1]:
				cnt += 1
	return cnt
n = int(input())
lst = []
for _ in range(n):
	lst.append(list(map(int, input().rstrip().split())))
print(gameDresses(n, lst))


num = int(input())
lst = []
for i in range(num):
	(a, b) = input().split()
	(a, b) = (int(a), int(b))
	lst.append(a)
	lst.append(b)
s = 0
for i in range(len(lst)):
	p = i % 2
	j = i + 1
	while j < len(lst):
		if j % 2 != p and lst[i] == lst[j]:
			s = s + 1
		j = j + 1
print(s)


t = int(input())
hl = []
gl = []
for _ in range(t):
	(h, g) = map(int, input().split())
	hl.append(h)
	gl.append(g)
c = 0
for h in range(t):
	for g in range(t):
		if hl[h] == gl[g] and h != g:
			c += 1
print(c)


n = int(input())
(d, g) = ([], [])
cnt = 0
for i in range(n):
	s = input().split()
	if s[0] in g:
		cnt += g.count(s[0])
	if s[-1] in d:
		cnt += d.count(s[-1])
	d.append(s[0])
	g.append(s[-1])
print(cnt)


n = int(input())
res = 0
homeColor = []
guestColor = []
for i in range(0, n):
	(x, y) = [int(j) for j in input().split()]
	homeColor.append(x)
	guestColor.append(y)
for x in homeColor:
	for i in range(0, n):
		if x == guestColor[i]:
			res += 1
print(res)


def uniforms():
	n = int(input())
	loc = []
	vis = []
	for i in range(n):
		test = [int(i) for i in input().split()]
		loc.append(test[0])
		vis.append(test[1])
	res = 0
	for e in loc:
		for j in vis:
			if e == j:
				res += 1
	return res
print(str(uniforms()))


a = int(input())
h = []
k = []
ans = 0
for i in range(a):
	(v, g) = list(map(int, input().split()))
	h.append(v)
	k.append(g)
for i in range(a):
	for y in range(a):
		if i != y and h[i] == k[y]:
			ans += 1
print(ans)


T = int(input())
i = 0
home = []
guest = []
for i in range(T):
	b = input().split()
	home.append(b[0])
	guest.append(b[1])
i = 0
j = 0
count = 0
for i in range(T):
	for j in range(T):
		if home[i] == guest[j]:
			count += 1
print(count)


n = int(input())
lt = []
s = 0
for i in range(n):
	lt.append(input().split())
for i in range(n):
	for j in range(i + 1, n):
		if lt[i][0] == lt[j][1]:
			s += 1
		if lt[i][1] == lt[j][0]:
			s += 1
print(s)


n = int(input())
l = []
for i in range(n):
	q = list(input().split())
	q = [int(j) for j in q]
	l.append(q)
steps = 0
for i in range(n - 1):
	for j in range(i, n - 1):
		if l[i][0] == l[j + 1][1] and l[i][1] == l[j + 1][0]:
			steps += 2
		elif l[i][0] == l[j + 1][1] or l[i][1] == l[j + 1][0]:
			steps += 1
print(steps)


import sys
import itertools
n = int(sys.stdin.readline().split()[0])
colours = [[0 for x in range(2)] for y in range(n)]
row = 0
for line in sys.stdin:
	column = 0
	for word in line.split():
		colours[row][column] = int(word)
		column += 1
	row += 1
guest_uniform = 0
matches = list(itertools.combinations(range(n), 2))
for match in matches:
	host_team = match[0]
	guest_team = match[1]
	if colours[host_team][0] == colours[guest_team][1]:
		guest_uniform += 1
	host_team = match[1]
	guest_team = match[0]
	if colours[host_team][0] == colours[guest_team][1]:
		guest_uniform += 1
print(guest_uniform)


n = int(input())
di = {}
li = []
for _ in range(n):
	(h, a) = map(int, input().split())
	li.append(h)
	di[a] = di.get(a, 0) + 1
count = 0
for i in li:
	count = count + 1 * di.get(i, 0)
print(count)


a = []
b = []
for _ in range(int(input())):
	(c, d) = map(int, input().split())
	a.append(c)
	b.append(d)
co = 0
for i in a:
	co = co + b.count(i)
print(co)


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


n = int(input())
(x, y) = zip(*[input().split() for i in ' ' * n])
print(sum([x.count(i) for i in y]))


n = int(input())
home = []
guest = []
s = 0
for _ in range(n):
	(h, g) = list(map(int, input().split()))
	home.append(h)
	guest.append(g)
for i in range(n):
	x = guest.count(home[i])
	s = s + x
print(s)


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


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())
team = []
a = []
for i in range(n):
	h = input().split()
	team.append(h)
	a.append(i)
x = 0
for i in range(n):
	a.remove(i)
	for j in range(n - 1):
		if team[i][0] == team[a[j]][1]:
			x += 1
		else:
			continue
	a.insert(i, i)
print(x)


num = int(input())
arr = [[0] * 2 for _ in range(num)]
h = []
a = []
count = 0
for i in range(num):
	arr[i] = list(map(int, input().split()))
for i in range(num):
	for j in range(1, num):
		if i + j >= num:
			break
		if arr[i][0] == arr[j + i][1]:
			count += 1
		if arr[i][1] == arr[j + i][0]:
			count += 1
print(count)


n = int(input())
home = [0] * n
away = [0] * n
for i in range(n):
	(home[i], away[i]) = [int(x) for x in input().split()]
total = 0
for a in away:
	total += home.count(a)
print(total)


n = int(input())
home = []
away = []
counter = 0
for _ in range(n):
	(h, a) = map(int, input().split())
	home.append(h)
	away.append(a)
for i in home:
	for y in away:
		if i == y:
			counter += 1
print(counter)


n = int(input())
list = []
for i in range(n):
	add = input().split()
	list.append(add)
res = 0
for i in range(n):
	for j in range(n):
		if j == i:
			continue
		if list[i][0] == list[j][1]:
			res += 1
print(res)


n = int(input())
lst1 = list()
lst2 = list()
for i in range(n):
	(a, b) = map(int, input().split())
	lst1.append(a)
	lst2.append(b)
c = 0
for i in lst1:
	for j in lst2:
		if j == i:
			c += 1
print(c)


t = int(input())
clothes = []
count = 0
for i in range(0, t):
	y = input()
	x = tuple(list(filter(lambda x: x != ' ', y.split(' '))))
	clothes.append(x)
for i in range(0, len(clothes)):
	for j in range(0, len(clothes)):
		if i == j:
			continue
		if clothes[i][0] == clothes[j][1]:
			count += 1
print(count)


n = int(input())
D = [tuple(map(int, input().split())) for i in range(n)]
count = 0
for i in range(len(D)):
	for j in range(i + 1, len(D)):
		if D[i][0] == D[j][1]:
			count += 1
		if D[i][1] == D[j][0]:
			count += 1
print(count)


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


n = int(input())
s1 = []
for i in range(n):
	(a, b) = map(int, input().split())
	s1.append(a)
	s1.append(b)
l = len(s1)
i = count = 0
while i < l:
	j = 1
	while j < l:
		if s1[i] == s1[j]:
			count += 1
		j += 2
	i += 2
print(count)


L = [list(map(int, input().split())) for u in range(int(input()))]
print(len([1 for i in [x[0] for x in L] for j in [x[1] for x in L] if i == j]))


x = input()
lines = ''
for i in range(int(x)):
	lines += input() + '\n'
y = lines.split()
count = 0
d = 0
z = list()
c = list()
for n in y:
	if d % 2 == 0:
		z.append(y[d])
	else:
		c.append(y[d])
	d = d + 1
for nu in z:
	for ni in c:
		if nu == ni:
			count = count + 1
print(count)


n = int(input())
map = {}
away = []
for i in range(n):
	(h, a) = [int(x) for x in input().split()]
	away.append(a)
	if h in map:
		map[h] += 1
	else:
		map[h] = 1
count = 0
for team in away:
	try:
		count += map[team]
	except KeyError:
		pass
print(count)


home = []
guest = []
for k in range(int(input())):
	(m, n) = map(int, input().split())
	home.append(m)
	guest.append(n)
sum = 0
for f in home:
	for l in guest:
		if f == l:
			sum += 1
print(sum)


import sys

def data():
	return sys.stdin.readline().strip()

def sp():
	return map(int, data().split())

def l():
	return list(sp())

def ans(arr):
	s = 0
	games = len(arr) * (len(arr) - 1)
	home = {}
	away = {}
	for i in range(1, 101):
		home[i] = 0
		away[i] = 0
		for (x, y) in enumerate(arr):
			if i == y[0]:
				home[i] += 1
			elif i == y[1]:
				away[i] += 1
	for i in range(1, 101):
		p = home[i] * away[i]
		s += p
	return s
n = int(data())
arr = []
for _ in range(n):
	arr.append(l())
print(ans(arr))


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


n = int(input())
l1 = []
k = 0
for i in range(n):
	l2 = [int(num) for num in input().split(' ')]
	l1.append(l2)
for i in l1:
	for j in l1:
		if i[1] == j[0]:
			k += 1
print(k)


x = int(input())
lis = []
li = []
counter = 0
for i in range(0, x):
	reg = input().split(' ')
	lis.append(int(reg[0]))
	li.append(int(reg[1]))
for l in range(0, len(lis)):
	for m in range(0, len(li)):
		if lis[l] == li[m]:
			counter += 1
print(counter)


n = int(input())
arrayD = []
arrayV = []
count = 0
for i in range(0, n):
	(d, v) = map(int, input().split())
	arrayD.append(d)
	arrayV.append(v)
for i in range(0, n):
	count += arrayD.count(arrayV[i])
print(count)


m = int(input())
t = []
for _ in range(m):
	(h1, g1) = map(int, input().split())
	t.append((h1, g1))
w = 0
l = len(t)
for tm1 in range(l):
	for tm2 in range(tm1 + 1, l):
		if t[tm1][0] == t[tm2][1]:
			w += 1
		if t[tm1][1] == t[tm2][0]:
			w += 1
print(w)


n = int(input())
teams = []
for i in range(n):
	(x, y) = [int(a) for a in input().split()]
	teams.append(x)
	teams.append(y)
count = 0
num = len(teams)
for i in range(num):
	j = i + 1
	while j < num:
		if teams[i] == teams[j]:
			count += 1
		j += 2
print(count)


n_teams = int(input())
jerseys = []
for i in range(0, n_teams):
	jerseys += [int(n) for n in input().split()]
home = []
away = []
for i in range(0, n_teams * 2, 2):
	home.append(jerseys[i])
for i in range(1, n_teams * 2, 2):
	away.append(jerseys[i])
games = 0
for x in home:
	games += away.count(x)
print(games)


n = int(input())
l1 = []
l2 = []
count = 0
for i in range(n):
	(hi, ai) = map(int, input().split())
	l1.append(hi)
	l2.append(ai)
for i in range(n):
	for j in range(n):
		if l1[i] == l2[j]:
			count += 1
print(count)


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())
home_counts = {}
away_counts = {}
for i in range(n):
	curr = input().split()
	if curr[0] in home_counts:
		home_counts[curr[0]] += 1
	else:
		home_counts[curr[0]] = 1
	if curr[1] in away_counts:
		away_counts[curr[1]] += 1
	else:
		away_counts[curr[1]] = 1
count = 0
for j in away_counts:
	if j in home_counts:
		count += home_counts[j] * away_counts[j]
print(count)


n = int(input())
h = []
a = []
count = 0
for i in range(n):
	temp = [int(x) for x in input().split()]
	h.append(temp[0])
	a.append(temp[1])
for i in range(n):
	count += h.count(a[i])
print(count)


n = int(input())
(a, b) = ([], [])
for _ in range(n):
	(ai, bi) = input().split()
	a.append(ai)
	b.append(bi)
count = 0
for v in a:
	count += b.count(v)
print(count)


n = int(input())
a = []
b = []
c = []
ans = 0
for i in range(n):
	l = input()
	a = l.split(' ')
	b.append(int(a[0]))
	c.append(int(a[1]))
for j in range(n):
	ans += c.count(b[j])
print(ans)


teams = int(input())
uniform_colors = []
count = 0
for i in range(teams):
	uniform_colors.append([int(i) for i in input().split()])
for home_uniform_index in range(teams):
	for guest_uniform_index in range(teams):
		if uniform_colors[home_uniform_index][0] == uniform_colors[guest_uniform_index][1]:
			count += 1
print(count)


n = int(input())
hlist = []
glist = []
for i in range(0, n):
	list1 = input().split(' ')
	hlist.append(list1[0])
	glist.append(list1[1])
game = 0
for k in hlist:
	game += glist.count(k)
print(game)


n = int(input())
teams = []
host = []
guest = []
p = []
plays = []
s = 0
for i in range(n):
	u = list(map(int, input().split()))
	teams.append(u)
for i in teams:
	host.append(i[0])
for i in teams:
	guest.append(i[1])
for i in host:
	for j in guest:
		p = [i, j]
		plays.append(p)
for i in plays:
	if i[0] == i[1]:
		s = s + 1
print(s)


n = int(input())
(h, a) = ([0] * n, [0] * n)
c = 0
for i in range(n):
	(h[i], a[i]) = [int(x) for x in input().split()]
for (kh, th) in enumerate(h):
	for (ka, ta) in enumerate(a):
		if kh == ka:
			continue
		if th == ta:
			c += 1
print(c)


from sys import stdin
n = int(stdin.readline())
l = []
for i in range(n):
	(h, a) = (int(x) for x in stdin.readline().strip().split(' '))
	l.append((h, a))
res = 0
for i in range(n):
	for j in range(n):
		if i == j:
			continue
		(hi, ai) = l[i]
		(hj, aj) = l[j]
		if hi == aj:
			res += 1
print(res)


t = int(input())
(m, n) = ([], [])
for i in range(t):
	q = list((int(x) for x in input().split()))
	m.append(q[0])
	n.append(q[1])
j = 0
for s in m:
	for t in n:
		if s == t:
			j += 1
print(j)


n = int(input())
team_colors = []
for i in range(0, n):
	(a, b) = input().split()
	a = int(a)
	b = int(b)
	c = [a, b]
	team_colors.extend(c)
counter = 0
for i in range(0, n):
	for j in range(0, n):
		if i != j:
			if team_colors[2 * i] == team_colors[2 * j + 1]:
				counter += 1
print(counter)


n = int(input())
host = []
gust = []
c = 0
for i in range(n):
	(a, b) = input().split()
	host.append(a)
	gust.append(b)
for i in gust:
	c += host.count(i)
print(c)


n = int(input())
a = []
count = 0
for i in range(n):
	s = list(map(int, input().split()))
	a.append(s)
for i in a:
	for j in range(n - 1):
		if i[0] == a[j + 1][1] and i[1] == a[j + 1][0]:
			count += 2
		elif i[0] == a[j + 1][1] or i[1] == a[j + 1][0]:
			count += 1
	a[a.index(i)] = ['a', 'z']
print(count)


size = int(input())
(left, right) = ([], [])
c = 0

def splitIn2(x: list):
	global left, right
	left.append(x[0])
	right.append(x[1])
for i in range(size):
	splitIn2(input().split(' '))
for i in range(size):
	c += right.count(left[i])
print(c)


n = int(input())
lst = []
num = 0
for i in range(n):
	xi = [int(x) for x in input().split()]
	lst.append(xi)
for i in range(n):
	x = lst[i]
	for m in range(n):
		if m != i:
			y = lst[m]
			if x[0] == y[1]:
				num += 1
print(num)


(m, n) = ([], [])
for i in range(int(input())):
	(a, b) = map(int, input().split())
	m.append(a)
	n.append(b)
r = 0
for i in m:
	r += n.count(i)
print(r)


n = int(input())
s = 0
tab = [[0 for i in range(2)] for j in range(n)]
for j in range(n):
	l = input().split()
	tab[j][0] = l[0]
	tab[j][1] = l[1]
for i in range(n):
	for j in range(n):
		if tab[i][0] == tab[j][1]:
			s += 1
print(s)


n = int(input())
h = [0] * n
g = [0] * n
for i in range(n):
	(tmp1, tmp2) = map(int, input().split())
	h[i] = tmp1
	g[i] = tmp2
ans = 0
for i in h:
	for j in g:
		if i == j:
			ans += 1
print(ans)


n = int(input(''))
home = []
guest = []
c = 0
for i in range(1, n + 1):
	(a, b) = map(int, input().split())
	home.append(a)
	guest.append(b)
for i in range(0, n):
	for j in range(0, n):
		if i != j:
			if home[i] == guest[j]:
				c = c + 1
print(c)


teams = int(input())
uniforms = []
for t in range(teams):
	dress = list(map(int, input().split()))
	uniforms.append(dress)
changes = 0
for x in range(teams):
	for y in range(teams):
		if x != y and uniforms[x][1] == uniforms[y][0]:
			changes += 1
print(changes)


n = int(input())
l = []
m = []
while n:
	(a, b) = map(int, input().split())
	l.append(a)
	m.append(b)
	n -= 1
c = 0
for i in l:
	c += m.count(i)
print(c)


n = int(input())
col = []
for i in range(n):
	(a, b) = map(int, input().split(' '))
	col.append((a, b))
nb = 0
for h in col:
	for a in col:
		if a != h and h[0] == a[1]:
			nb += 1
print(nb)


t = int(input())
p = []
for i in range(t):
	h = list(map(int, input().split()))
	p.append(h)
count = 0
for i in range(t):
	for j in range(t):
		if p[i][0] == p[j][1]:
			count += 1
print(count)


n = int(input())
arr = [0] * n
brr = [0] * n
for i in range(n):
	(arr[i], brr[i]) = map(int, input().split())
ans = 0
for i in range(n):
	for j in range(n):
		if arr[i] == brr[j]:
			ans += 1
print(ans)


import itertools
n = int(input())
teams = [input().split() for _ in range(n)]
games = itertools.permutations(teams, 2)
count = 0
for g in games:
	if g[0][0] == g[1][1]:
		count += 1
print(count)


n = int(input())
home = []
guest = []
for i in range(n):
	line = input().split()
	home.append(line[0])
	guest.append(line[1])
ans = 0
for h in home:
	ans += guest.count(h)
print(ans)


import itertools
n = int(input())
teams = []
events = 0
for x in range(n):
	teams.append(list(map(int, input().split(' '))))
games = itertools.permutations(teams, 2)
for y in games:
	if y[0][0] == y[1][1]:
		events += 1
print(events)


n = int(input())
team = [0] * n
for i in range(n):
	inputs = list(map(int, input().split()))
	team[i] = inputs
result = 0
for i in range(n):
	hostC = team[i][0]
	for j in range(n):
		if i == j:
			continue
		guestC = team[j][1]
		if hostC == guestC:
			result += 1
print(result)


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


n = int(input())
list1 = []
count = 0
for m in range(n):
	list1.append(list(map(int, input().split())))
for element1 in list1:
	for element2 in list1:
		if element1[0] == element2[1]:
			count += 1
print(count)


n = int(input())
a = [0] * 100
b = [0] * 100
for i in range(n):
	(a[i], b[i]) = map(int, input().split())
ans = 0
for i in range(n - 1):
	for j in range(i + 1, n):
		if a[i] == b[j]:
			ans += 1
		if a[j] == b[i]:
			ans += 1
print(ans)


import sys
import sys

def data():
	return sys.stdin.readline().strip()

def sp():
	return map(int, data().split())

def l():
	return list(sp())

def ans(arr, n):
	c = 0
	home = []
	away = []
	for (x, y) in enumerate(arr):
		home.append(y[0])
		away.append(y[1])
	for i in range(0, n):
		for j in range(0, n):
			if i != j and home[i] == away[j]:
				c += 1
	return c
n = int(data())
arr = []
for _ in range(n):
	arr.append(l())
print(ans(arr, n))


n = int(input())
s = list()
for a in range(n):
	s.append(input().split(' '))
c = 0
for t in s:
	for q in s:
		if t[0] == q[1]:
			c += 1
print(c)


n = int(input())
hlist = []
alist = []
count = 0
for _ in range(n):
	(h, a) = map(int, input().split())
	hlist.append(h)
	alist.append(a)
for i in range(n):
	for j in range(n):
		if hlist[i] == alist[j]:
			count += 1
print(count)


n = input()
h = []
g = []
s = 0
for i in range(int(n)):
	(a, b) = (int(i) for i in input().split())
	h.append(a)
	g.append(b)
for i in h:
	s += g.count(i)
print(s)


n = int(input())
ar = []
br = []
for i in range(n):
	ar.append(0)
	br.append(0)
	(ar[i], br[i]) = map(int, input().split())
c = 0
for i in range(0, n):
	for j in range(0, n):
		if i != j and ar[i] == br[j]:
			c += 1
print(c)


n = int(input())
l = []
for i in range(n):
	(a, b) = map(int, input().split())
	l1 = []
	l1.append(a)
	l1.append(b)
	l.append(l1)
c = 0
for i in range(len(l) - 1):
	for j in range(i + 1, len(l)):
		if l[i][0] == l[j][1] and l[i][1] == l[j][0]:
			c += 2
		elif l[i][0] == l[j][1] or l[i][1] == l[j][0]:
			c += 1
		else:
			continue
print(c)


(b, c, d, e) = ([], [], [], [])
f = 0
n = int(input())
while n > 0:
	v = [int(x) for x in input().split(' ')]
	b = b + v
	n -= 1
c = b[0:-1:2]
d = b[1:len(b):2]
for x in c:
	e.append(d.count(x))
for x in e:
	f += x
print(f)


N = int(input())
lista = []
lista1 = []
contador = 0
for i in range(N):
	(a, b) = map(int, input().split())
	lista += [a]
	lista1 += [b]
for i in range(len(lista)):
	for j in range(len(lista1)):
		if lista[i] == lista1[j]:
			contador += 1
print(contador)


games = int(input())
home = list()
guest = list()
count = 0
for i in range(games):
	(x, y) = map(int, input().split(' '))
	home.append(x)
	guest.append(y)
for i in range(games):
	for j in range(games):
		if home[i] == guest[j]:
			count += 1
print(count)


n = int(input())
a = []
for i in range(n):
	a.append([int(a) for a in input().split()])
count = 0
s1 = []
s2 = []
for i in range(n):
	for j in range(2):
		if j == 0:
			s1.append(a[i][j])
		else:
			s2.append(a[i][j])
su = []
for i in range(n):
	if s2[i] != 0:
		if s2[i] in s1:
			su.append(s1.count(s2[i]))
print(sum(su))


n = int(input())
(l1, l2) = ([], [])
for i in range(n):
	s = [int(x) for x in input().split()]
	l1.append(s[0])
	l2.append(s[1])
g = 0
for i in l1:
	g = g + l2.count(i)
print(g)


n = int(input())
(l, p) = ([], [])
while n > 0:
	n -= 1
	line = input()
	(a, b) = [int(x) for x in line.split()]
	l.append(a)
	p.append(b)
ans = 0
for i in l:
	ans += p.count(i)
print(ans)


n = int(input())
car = []
for i in range(n):
	(a, b) = map(int, input().split(' '))
	car.append((a, b))
cou = 0
for i in range(len(car)):
	for k in car:
		if car[i][1] == k[0]:
			cou += 1
print(cou)


n = int(input())
i = 0
a = []
b = []
while i < n:
	(t, d) = input().split()
	t = int(t)
	d = int(d)
	a.append(t)
	b.append(d)
	i = i + 1
l = 0
i = 0
while i < n:
	j = 0
	while j < n:
		if i != j:
			if a[i] == b[j]:
				l += 1
		j = j + 1
	i = i + 1
print(l)


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


team = int(input())
host = []
guest = []
for i in range(team):
	(n, m) = map(int, input().split())
	host.append(n)
	guest.append(m)
count = 0
for i in range(len(host)):
	p = host[i]
	for j in range(len(guest)):
		if p == guest[j]:
			count += 1
print(count)


n = int(input())
tab = []
sec = []
x = 0
for i in range(n):
	(h, g) = input().split()
	tab.append(h)
	sec.append(g)
for p in range(len(tab)):
	if tab[p] in sec:
		x += sec.count(tab[p])
print(x)


n = int(input())
h = []
a = []
output = 0
for i in range(n):
	(x, y) = [int(x) for x in input().split()]
	h.append(x)
	a.append(y)
for j in range(n):
	for k in range(n):
		if h[j] == a[k]:
			output += 1
		k += 1
	j += 1
print(output)


n = int(input())
a = [input().split() for _ in range(n)]
cnt = 0
for (tm_h, tm_a) in a:
	cnt += sum([1 for (th, ta) in a if tm_h == ta])
print(cnt)


l = []
s = []
for _ in range(int(input())):
	(n, k) = input().split()
	l.append(n)
	s.append(k)
count = 0
for i in l:
	count += s.count(i)
print(count)


home = []
guest = []
for n in range(int(input())):
	(x, y) = map(int, input().split())
	home.append(x)
	guest.append(y)
count = 0
for i in range(len(guest)):
	for j in range(len(home)):
		if guest[i] == home[j]:
			count += 1
print(count)


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


x = int(input())
q = []
p = 0
count = 0
while x > p:
	p += 1
	y = input().split()
	for i in y:
		q.append(i)
for i in range(0, len(q), 2):
	for j in range(1, len(q), 2):
		if q[i] == q[j]:
			count += 1
print(count)


cantidad = int(input())
L1 = []
L2 = []
veces = 0
while cantidad > 0:
	equipo = input()
	num = ''
	for numero in equipo:
		if numero != ' ':
			num = num + numero
		else:
			L1.append(int(num))
			num = ''
	L2.append(int(num))
	cantidad -= 1
for home in L1:
	for visita in L2:
		if home == visita:
			veces += 1
print(veces)


matches = int(input())
ans = 0
(home, guest) = ([], [])
for i in range(matches):
	(a, b) = input().split()
	home.append(a)
	guest.append(b)
for i in home:
	for j in guest:
		if i == j:
			ans += 1
print(ans)


t = int(input())
k = []
b = []
res = 0
n = 0
while n < t:
	(x, y) = input().split()
	x = int(x)
	y = int(y)
	k.append(x)
	b.append(y)
	n += 1
for i in range(t):
	for j in range(t):
		if k[i] == b[j]:
			res += 1
print(res)


n = int(input())
A = []
B = []
for i in range(n):
	(a, b) = input().split(' ')
	a = int(a)
	b = int(b)
	A.append(a)
	B.append(b)
x = 0
for i in range(n):
	y = A[i]
	for i in range(n):
		if y == B[i]:
			x = x + 1
print(x)


n = int(input())
a = []
b = []
for _ in range(n):
	(c, d) = map(int, input().split())
	a = a + [c]
	b = b + [d]
print(sum((b.count(i) for i in a)))


t = int(input())
l = []
s = 0
for i in range(t):
	l.append(tuple(map(int, input().split())))
for i in range(t - 1):
	for j in range(i + 1, t):
		if l[i][0] == l[j][1]:
			s += 1
		if l[i][1] == l[j][0]:
			s += 1
print(s)


n = int(input())
h = []
a = []
for i in range(n):
	l = input().split()
	h.append(l[0])
	a.append(l[1])
print(sum((a.count(u) for u in h if u in a)))


n = int(input())
teams = []
for _ in range(n):
	teams.append(tuple(map(int, input().split())))
res = 0
for team in teams:
	for team2 in teams:
		if team[0] == team2[1]:
			res += 1
print(res)


b = int(input())
a = []
c = 0
for i in range(b):
	a.append(list((int(x) for x in input().split())))
for i in range(b):
	for j in range(b):
		if a[i][1] == a[j][0]:
			c += 1
print(c)


import copy
import collections

class Team:

	def __init__(self, home, guest):
		self.home = home
		self.guest = guest
n = int(input())
result = 0
teams = []
for i in range(n):
	(h, g) = list(map(int, input().split()))
	teams.append(Team(h, g))
for i in range(n):
	copyTeam = copy.copy(teams)
	copyTeam.pop(i)
	for t in copyTeam:
		if t.guest == teams[i].home:
			result += 1
print(result)


x = int(input())
a = [None] * x
b = [None] * x
for i in range(x):
	(a[i], b[i]) = map(int, input().split())
k = 0
for i in range(x):
	for j in range(x):
		if a[i] == b[j] and i != j:
			k += 1
print(k)


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


n = int(input())
k = []
i = 0
while i < n:
	(a, b) = [int(i) for i in input().split()]
	k.append((a, b))
	i += 1
c = 0
for i in range(len(k)):
	for j in range(len(k)):
		if k[i][0] == k[j][1]:
			c += 1
print(c)


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


a = int(input())
D = {}
for i in range(a):
	D[i] = list(map(int, input().split()))
count = 0
for i in D:
	b = D[i][0]
	for j in D:
		if D[j][1] == b:
			count += 1
		else:
			pass
print(count)


def main():
	n = int(input())
	A = []
	H = []
	ans = 0
	for _ in range(n):
		(a, h) = list(map(int, input().split()))
		A.append(a)
		H.append(h)
	for i in range(n):
		for j in range(n):
			if i != j and H[i] == A[j]:
				ans += 1
	print(ans)
main()


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


import io, os
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
n = int(input())
g = []
for i in range(n):
	g.append(tuple(map(int, input().split())))
ct = 0
for i in range(n):
	for j in range(i + 1, n):
		if g[i][0] == g[j][1]:
			ct += 1
		if g[i][1] == g[j][0]:
			ct += 1
print(ct)


n = int(input())
A = []
for i in range(n):
	A.append(input().split())
out = 0
for i in range(n):
	for j in range(n):
		if i != j and A[i][0] == A[j][1]:
			out += 1
print(out)


n = int(input())
h = []
g = []
for i in range(n):
	s = input().split()
	h += [s[0]]
	g += [s[1]]
cnt = 0
for i in range(n):
	for j in range(n):
		if i != j and h[i] == g[j]:
			cnt += 1
print(cnt)


li = []
for i in range(int(input())):
	li.append(tuple(map(int, input().split(' '))))
count = 0
for i in range(len(li)):
	for j in range(i + 1, len(li)):
		if li[j][1] == li[i][0]:
			count += 1
		if li[j][0] == li[i][1]:
			count += 1
print(count)


n = int(input())
listaVisitante = []
listaCasa = []
for i in range(n):
	temp = list(map(int, input().split(' ')))
	listaVisitante.append(temp[1])
	listaCasa.append(temp[0])
res = 0
for i in listaCasa:
	res += listaVisitante.count(i)
print(res)


n = int(input())
l = []
while n > 0:
	n -= 1
	(a, b) = [int(i) for i in input().split()]
	l.append((a, b))
t = 0
for i in range(len(l)):
	for j in range(len(l)):
		if l[i][0] == l[j][1]:
			t += 1
print(t)


list1 = []
k = int(input())
count = 0

def match(m, n, count):
	if m[0][0] == n[0][1]:
		count += 1
	if m[0][1] == n[0][0]:
		count += 1
	return count
for i in range(k):
	list1.append([])
	list1[i].append(list(map(int, input().split())))
for i in range(len(list1) - 1):
	for j in list1[i + 1:]:
		count = match(list1[i], j, count)
print(count)


n = int(input())
a = list()
sum = 0
for i in range(n):
	ele = input().split()
	a.append(ele)
for i in range(n):
	for j in range(n):
		if i == j:
			continue
		if a[i][0] == a[j][1]:
			sum += 1
print(sum)


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


h = []
g = []
n = int(input())
for _ in range(n):
	(x, y) = map(int, input().split())
	h.append(x)
	g.append(y)
c = 0
for i in range(n):
	for j in range(n):
		if h[i] == g[j]:
			c += 1
print(c)


n = int(input())
homes = []
guests = []
for t in range(n):
	s = input().split(' ')
	homes.append(s[0])
	guests.append(s[1])
sum = 0
for i in homes:
	if i in guests:
		sum += guests.count(i)
print(sum)


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


from sys import stdin, stdout
n = int(stdin.readline())
lis = []
for i in range(n):
	lis.append([int(x) for x in stdin.readline().split(' ')])
c = 0
for each in lis:
	c += [x[1] for x in lis].count(each[0])
stdout.write('{}\n'.format(c))


n = int(input())
h = []
a = []
res = 0
for i in range(n):
	(temp1, temp2) = map(int, input().split(' '))
	h.append(temp1)
	a.append(temp2)
for i in range(n):
	res += h.count(a[i])
print(res)


l = []
for _ in range(int(input())):
	l.append(list(map(int, input().split())))
c = 0
for i in range(len(l)):
	for j in range(len(l)):
		if i != j:
			if l[i][0] == l[j][1]:
				c = c + 1
print(c)


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


import sys
lines = sys.stdin.readlines()
N = int(lines[0].strip())
home = {}
away = {}
for i in range(1, N + 1):
	(a, b) = map(int, lines[i].strip().split(' '))
	if a not in home:
		home[a] = 0
	if b not in away:
		away[b] = 0
	home[a] += 1
	away[b] += 1
res = 0
for k in home.keys():
	if k in away:
		res += home[k] * away[k]
print(res)


from __future__ import division, print_function
from collections import *
from math import *
from itertools import *
from time import time
import os
import sys
from io import BytesIO, IOBase
if sys.version_info[0] < 3:
	from __builtin__ import xrange as range
	from future_builtins import ascii, filter, hex, map, oct, zip

def main():
	n = int(input())
	TJ = list()
	for _ in range(n):
		(h, a) = map(int, input().split())
		TJ.append((h, a))
	Count = 0
	for HTI in range(n):
		for ATI in range(n):
			if HTI == ATI:
				continue
			HTJ = TJ[HTI][0]
			ATJ = TJ[ATI][1]
			if HTJ == ATJ:
				Count += 1
	print(Count)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


home = []
away = []
count = 0
n = int(input())
for _ in range(n):
	(a, b) = map(int, input().split())
	home.append(a)
	away.append(b)
for i in home:
	for j in away:
		if i == j:
			count += 1
print(count)


n = int(input())
rumah = []
tamu = []
total = 0
for i in range(n):
	tanding = input().split()
	rumah.append(tanding[0])
	tamu.append(tanding[1])
for i in range(len(rumah)):
	for j in range(len(tamu)):
		if rumah[i] == tamu[j]:
			total += 1
print(total)


n = int(input())
l1 = []
l2 = []
count = 0
for i in range(n):
	teams = [int(n) for n in input().split()]
	l1.append(teams[0])
	l2.append(teams[1])
for i in range(n):
	for j in range(n):
		if l1[i] == l2[j]:
			count += 1
print(count)


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


n = int(input())
data = [input().split() for _ in range(n)]
i = 0
k = 0
for x in data:
	i += 1
	for y in data[i:]:
		if x[0] == y[1]:
			k += 1
i = 0
for y in data:
	i += 1
	for x in data[i:]:
		if x[0] == y[1]:
			k += 1
print(k)


n = int(input().strip())
x = []
while n != 0:
	n -= 1
	(a, b) = map(int, input().strip().split())
	x.append((a, b))
c = 0
for i in range(len(x) - 1):
	for j in range(i + 1, len(x)):
		if x[i][1] == x[j][0]:
			c += 1
		if x[i][0] == x[j][1]:
			c += 1
print(c)


x = int(input())
arrh = []
arrg = []
for i in range(x):
	c = input()
	c = c.split(' ')
	arrh.append(c[0])
	arrg.append(c[1])
counter = 0
for i in arrg:
	for x in arrh:
		if x == i:
			counter = counter + 1
print(counter)


n = int(input())
H = []
A = []
for tc in range(n):
	(h, a) = [int(x) for x in input().split()]
	H.append(h)
	A.append(a)
c = 0
for num in H:
	c += A.count(num)
print(c)


n = int(input())
x = [[0] * 2 for i in range(n)]
for i in range(n):
	(x[i][0], x[i][1]) = map(int, input().split())
c = 0
for i in range(n):
	for j in range(n):
		if i != j:
			if x[i][0] == x[j][1]:
				c = c + 1
print(c)


n = int(input())
l = [list(map(int, input().split())) for i in range(n)]
p = [i[0] for i in l]
s = [i[1] for i in l]
count = sum([s.count(p[i]) for i in range(len(p)) if p[i] in s])
print(count)


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


n = int(input())
home = []
guest = []
for i in range(0, n):
	(h, g) = map(int, input().split())
	home.append(h)
	guest.append(g)
same_clr = 0
for i in range(0, n):
	for j in range(0, n):
		if i != j and home[i] == guest[j]:
			same_clr += 1
print(same_clr)


n = int(input())
zero = []
one = []
count = 0
for i in range(n):
	j = list(map(int, input().split(' ')))
	zero.append(j[0])
	one.append(j[1])
for i in zero:
	count += one.count(i)
print(count)


n = int(input())
c = 0
H = []
G = []
for i in range(n):
	(h, g) = map(int, input().split())
	H.append(h)
	G.append(g)
for h in H:
	for g in G:
		if h == g:
			c += 1
print(c)


n = int(input())
l = []
for _ in range(n):
	(h, a) = map(int, input().split())
	l.append([h, a])
c = 0
for i in range(n):
	for j in range(n):
		if i != j and l[i][0] == l[j][1]:
			c += 1
print(c)


import re
n = int(input())
color = [re.findall('\\d+\\s', input() + ' ') for i in range(n)]
time = 0
for i in range(n):
	for j in range(n):
		if color[i][0] == color[j][1]:
			time += 1
print(time)


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


n = int(input())
l1 = []
l2 = []
c = 0
for i in range(n):
	s = input()
	p = s.split()
	l1.append(int(p[0]))
	l2.append(int(p[1]))
for i in l1:
	for j in l2:
		if i == j:
			c += 1
print(c)


n = int(input())
a_list = []
for _ in range(n):
	s = input()
	t = s.split(' ')
	t = list(map(lambda x: int(x), t))
	a_list.append(t)
res = 0
for i in range(n):
	for j in range(n):
		if i != j and a_list[i][0] == a_list[j][1]:
			res += 1
print(res)


n = int(input())
a = []
b = []
for i in range(n):
	(tmp_a, tmp_b) = [int(tmp_a) for tmp_a in input().split()]
	a.append(tmp_a)
	b.append(tmp_b)
sum = 0
for i in a:
	tmp = b.count(i)
	sum += tmp
print(sum)


n = int(input())
colours = []
for x in range(n):
	a = [int(i) for i in input().split()]
	colours.append(a)
num = 0
for t1 in colours:
	for t2 in colours:
		if t1 == t2:
			pass
		elif t1[0] == t2[1]:
			num += 1
print(num)


n = int(input())
arr = [0] * n
count = 0
for i in range(n):
	arr[i] = input().split()
for i in range(n):
	for j in range(n):
		if arr[i][0] == arr[j][1]:
			count += 1
		else:
			pass
print(count)


n = int(input())
home = []
away = []
counter = 0
for i in range(0, n):
	(x, y) = input().split()
	x = int(x)
	y = int(y)
	home.append(x)
	away.append(y)
for i in range(0, n):
	for x in range(0, n):
		if home[i] == away[x] and i != x:
			counter += 1
print(counter)


n = int(input())
lista = []
home = []
guest = []
matches = 0
for contador in range(n):
	(h, a) = input().split(' ')
	home.append(h)
	guest.append(a)
lista.append(home)
lista.append(guest)
for x in lista[0]:
	for y in lista[1]:
		if x == y:
			matches += 1
print(matches)


n = int(input())
x = list()
y = list()
while n > 0:
	l = [int(x) for x in input().split()]
	x.append(l[0])
	y.append(l[1])
	n -= 1
d = 0
for i in x:
	for j in y:
		if i == j:
			d += 1
print(d)


n = int(input())
h = []
g = []
c = 0
for i in range(n):
	(a, b) = map(int, input().split())
	h.append(a)
	g.append(b)
for i in range(n):
	hx = h[i]
	x = g[0:i] + g[min(n - 1, i + 1):]
	for j in x:
		if j == hx:
			c += 1
print(c)


n = int(input())
x = []
y = []
c = 0
for i in range(n):
	(a, b) = [int(i) for i in input().split()]
	x.append(a)
	y.append(b)
for j in range(n):
	p = y.count(x[j])
	c = c + p
print(c)


n = int(input())
col = []
ncount = 0
for i in range(n):
	col.append([int(x) for x in input().split()])
for j in col:
	for k in col:
		if j[0] == k[1]:
			ncount += 1
print(ncount)


import sys
n = int(input())
har = []
aar = []
suma = 0
for i in range(n):
	(h, a) = map(int, sys.stdin.readline().split())
	har.append(h)
	aar.append(a)
for j in range(n):
	suma += aar.count(har[j])
print(suma)


n = input()
n = int(n)
h = []
j = []
out = 0
games = n * (n - 1)
for i in range(n):
	x = []
	x = input()
	x = x.split()
	h.append(x[0])
	j.append(x[1])
for m in h:
	for k in j:
		if m == k:
			out += 1
print(out)


n = int(input())
a = [0 for i in range(101)]
b = [0 for i in range(101)]
for i in range(n):
	(x, y) = map(int, input().split())
	a[i] = x
	b[i] = y
sum = 0
for i in range(n):
	for j in range(n):
		if a[i] == b[j]:
			sum += 1
print(sum)


(h, a) = ([], [])
n = int(input())
for i in range(n):
	(hh, aa) = map(int, input().split())
	h += [hh]
	a += [aa]
r = 0
for i in range(0, n):
	for j in range(0, n):
		if i != j and h[i] == a[j]:
			r += 1
print(r)


n = int(input())
h = []
g = []
c = 0
for i in range(0, n):
	(h1, g1) = list(map(int, input().split()))
	h.append(h1)
	g.append(g1)
for i in range(0, n):
	for j in range(0, i):
		if h[i] == g[j]:
			c = c + 1
		if g[i] == h[j]:
			c = c + 1
print(c)


n = int(input())
x = []
for i in range(n):
	x.append(list(map(int, input().split())))
count = 0
for i in range(len(x)):
	for j in range(len(x)):
		if i != j:
			if x[i][0] == x[j][1]:
				count += 1
			if x[i][1] == x[j][0]:
				count += 1
print(count // 2)


n = int(input())
x = []
y = []
i = 0
while i < n:
	(h, a) = input().split()
	x.append(int(h))
	y.append(int(a))
	i += 1
l = 0
for k in x:
	l += y.count(k)
print(l)


n = int(input())
uniform = []
guestuniform = 0
for i in range(1, n + 1):
	tempt = [int(k) for k in input().split()]
	uniform.append(tempt)
for i in range(1, n + 1):
	for j in range(1, n + 1):
		if j == i:
			continue
		host = uniform[i - 1][0]
		guest = uniform[j - 1][1]
		if host == guest:
			guestuniform += 1
print(guestuniform)


num = int(input())
a = []
result = 0
for i in range(num):
	b = input()
	a.append(b.split())
for i in range(num):
	for j in range(num):
		if a[i][1] == a[j][0]:
			result += 1
print(result)


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


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


def colors(arr):
	count = 0
	for i in arr:
		for j in arr:
			if i[0] == j[1]:
				count += 1
	return count
n = int(input())
ar = []
for i in range(n):
	x = list(map(int, input().rstrip().split()))
	ar.append(x)
print(colors(ar))


n = int(input())
lst = []
for i in range(1, n + 1):
	ha = input().split()
	lst.append(ha)
lst1 = []
lst2 = []
for i in range(n):
	lst1.append(lst[i][0])
	lst2.append(lst[i][1])
counter = 0
for i in lst1:
	counter = counter + lst2.count(i)
print(counter)


a = int(input())
home = []
away = []
for i in range(a):
	x = list(map(int, input().split()))
	home.append(x[0])
	away.append(x[1])
counter = 0
for z in home:
	counter = counter + away.count(z)
print(counter)


n = int(input())
one = []
two = []
for _ in range(n):
	(a, b) = list(map(int, input().split()))
	one.append(a)
	two.append(b)
num = 0
for i in one:
	for j in two:
		if i == j:
			num += 1
print(num)


teams = int(input())
total = []
for i in range(teams):
	team = input().split()
	total.append(team)
count = 0
for i in range(teams):
	for j in range(teams):
		if total[i][0] == total[j][1]:
			count += 1
print(count)


n = int(input())
l = []
c = 0
for i in range(0, n):
	l.append(input().split())
for i in range(0, n):
	for j in range(i + 1, n):
		c += int(l[i][0] == l[j][1]) + int(l[i][1] == l[j][0])
print(c)


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


teams = int(input(''))
teams_colors = {}
for i in range(teams):
	colors = input('').split(' ')
	teams_colors[i] = (colors[0], colors[1])
count = 0
for (team_host, color_team_host) in teams_colors.items():
	for (team_guest, color_team_guest) in teams_colors.items():
		if team_host != team_guest:
			if color_team_host[0] == color_team_guest[1]:
				count += 1
print(count)


n = int(input())
host = [0] * n
guest = [0] * n
count = 0
for i in range(n):
	string = input()
	s = string.split(' ')
	host[i] = int(s[0])
	guest[i] = int(s[1])
for i in range(n):
	for j in range(n):
		if host[i] == guest[j]:
			count += 1
print(count)


a = int(input())
e = []
f = []
g = 0
for i in range(a):
	(c, d) = [*map(int, input().split())]
	e.append(c)
	f.append(d)
for i in range(a):
	for j in range(a):
		if e[i] == f[j]:
			g += 1
print(g)


n = int(input())
l = list()
ans = 0
for i in range(n):
	x = list(map(int, input().split()))
	l.append(x)
i = 0
j = 1
for i in range(n - 1):
	for j in range(i + 1, n):
		if l[i][0] == l[j][1] and l[i][1] == l[j][0]:
			ans += 2
		elif l[i][0] == l[j][1] or l[i][1] == l[j][0]:
			ans += 1
print(ans)


def fun(h, a, n):
	(dic, dic2) = ({}, {})
	for i in h:
		if i not in set(dic.keys()):
			dic[i] = 1
		else:
			dic[i] += 1
	for i in a:
		if i not in set(dic2.keys()):
			dic2[i] = 1
		else:
			dic2[i] += 1
	l = set(dic.keys()).intersection(set(dic2.keys()))
	s = 0
	for i in l:
		s += dic[i] * dic2[i]
	print(s)
n = int(input())
h = list()
a = list()
for i in range(n):
	(b, c) = list(map(lambda x: int(x), input().split()))
	h.append(b)
	a.append(c)
fun(h, a, n)


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


n = int(input())
num = 0
(a, b) = ([], [])
for i in range(n):
	c = input().split()
	a.append(c[0])
	b.append(c[1])
for i in a:
	num += b.count(i)
print(num)


n = int(input())
home = list()
guest = list()
c = 0
for i in range(0, n, 1):
	str1 = input().split()
	home.append(int(str1[0]))
	guest.append(int(str1[1]))
for i in range(0, n, 1):
	for j in range(0, n, 1):
		if j == i:
			continue
		elif home[i] == guest[j]:
			c += 1
print(c)


n = int(input())
(h, a) = zip(*[map(int, input().split()) for _ in range(n)])
print(sum((a.count(k) for k in h)))


n = int(input())
home = dict()
foreign = dict()
acc = 0
for _ in range(n):
	(h, f) = list(map(int, input().split()))
	home[h] = home.get(h, 0) + 1
	foreign[f] = foreign.get(f, 0) + 1
for key in home:
	acc = acc + home[key] * foreign.get(key, 0)
print(acc)


n = input()
game = []
for i in range(int(n)):
	j = input()
	p = j.split(' ')
	game.append(p)
games = 0
for a in range(len(game) - 1):
	la = game[a]
	lb = game[a + 1:]
	for b in lb:
		if la[0] == b[1]:
			games += 1
		if la[1] == b[0]:
			games += 1
print(games)


import sys
input = sys.stdin.readline

def main():
	n = int(input())
	A = tuple((tuple(map(int, input().rstrip().split())) for _ in range(n)))
	ans = 0
	for i in range(n):
		for j in range(n):
			if i == j:
				continue
			if A[i][0] == A[j][1]:
				ans += 1
	print(ans)
main()


N = int(input())
M = []
for _ in range(N):
	M.append([int(x) for x in input().split()])
count = 0
for x in M:
	tmp_list = [1 for y in M if y[1] == x[0]]
	count += len(tmp_list)
print(count)


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


n = int(input())
array = []
for i in range(0, n):
	array.append(str.split(input(), ' '))
res = 0
for i in range(0, n):
	host = int(array[i][0])
	for u in range(0, n):
		if u != i:
			if host == int(array[u][1]):
				res += 1
print(res)


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


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


import sys
input = sys.stdin.readline
n = int(input())
h = []
v = []
cnt = 0
for _ in range(n):
	(x, y) = input().split()
	h.append(x)
	v.append(y)
for i in range(n):
	for j in v[:i] + v[i + 1:]:
		if h[i] == j:
			cnt += 1
print(cnt)


n = int(input())
mat = []
res = 0
for i in range(n):
	x = list(map(int, input().split()))
	mat.append(x)
for i in range(n):
	for j in range(n):
		if i == j:
			continue
		elif mat[i][0] == mat[j][1]:
			res = res + 1
print(res)


N = int(input())
teams_colors = [[0] * 2] * N
for i in range(N):
	teams_colors[i] = input().split()
host_player = []
guest_player = []
number_of_games = 0
for i in range(N):
	host_player = teams_colors[i]
	for j in range(N):
		if j != i:
			guest_player = teams_colors[j]
			if host_player[0] == guest_player[1]:
				number_of_games += 1
print(number_of_games)


(ans, c, arr) = (0, 0, [])
for _ in range(int(input())):
	(a, b) = map(int, input().split())
	arr.append((a, b))
	c += 1
for i in range(c):
	for j in range(c):
		if i != j:
			if arr[i][0] == arr[j][1]:
				ans += 1
print(ans)


n = int(input())
array = []
for i in range(n):
	array.append([int(x) for x in input().split()])
sum = 0
for i in range(n):
	for j in range(n):
		if array[i][0] == array[j][1]:
			sum += 1
print(sum)


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


(a, b, c) = ([], [], set())
summ = 0
for _ in range(int(input())):
	(x, y) = map(int, input().split())
	a.append(x)
	c.add(x)
	b.append(y)
for i in c:
	summ += a.count(i) * b.count(i)
print(summ)


def game_num():
	team_num = int(input())
	forms = list()
	for a in range(team_num):
		current_form = input().split()
		forms.append((current_form[0], current_form[1]))
	result = 0
	for i in forms:
		home = i[0]
		for j in forms:
			away = j[1]
			if home == away:
				result += 1
	return result
print(game_num())


n = int(input())
harr = []
garr = []
for _ in range(n):
	(h, g) = map(int, input().split())
	harr.append(h)
	garr.append(g)
count = 0
for i in range(n):
	for j in range(n):
		if harr[i] == garr[j]:
			count += 1
print(count)


import copy

def main():
	n = int(input())
	teams = []
	change_uni = 0
	for i in range(0, n):
		(x, y) = input().split()
		teams.append((int(x), int(y)))
	for i in range(0, n):
		for j in range(0, n):
			if i != j:
				if teams[i][0] == teams[j][1]:
					change_uni = change_uni + 1
	print(change_uni)
main()


no_of_times = int(input())
list = []
guests = []
homes = []
x = 0
y = 1
answer = 0
games_h = -1
games_g = 0
for n in range(no_of_times):
	z = input()
	(h, g) = z.split(' ')
	list.append(h)
	list.append(g)
while y < len(list):
	homes.append(list[x])
	guests.append(list[y])
	x += 2
	y += 2
for n in range(no_of_times):
	games_g = 0
	games_h += 1
	for n in range(no_of_times):
		if games_h < len(guests):
			if homes[games_h] == guests[games_g]:
				answer += 1
			games_g += 1
print(answer)


n = int(input())
count = 0
home_clothes = []
guests_clothes = []
for i in range(n):
	(x, y) = map(int, input().split())
	home_clothes.append(x)
	guests_clothes.append(y)
for i in home_clothes:
	for j in guests_clothes:
		if i == j:
			count += 1
print(count)


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


def inlt():
	return list(map(int, input().split()))
n = int(input())
home = []
guest = []
for i in range(n):
	l = inlt()
	home.append(l[0])
	guest.append(l[1])
ans = 0
for i in range(n):
	for j in range(n):
		if home[i] == guest[j]:
			ans += 1
print(ans)


n = int(input())
k = [[int(i) for i in input().split()] for j in range(n)]
count = 0
for p in range(n):
	for q in range(n):
		if k[p][0] == k[q][1]:
			count += 1
print(count)


n = int(input())
host = []
guest = []
count = 0
for i in range(n):
	(n, m) = map(int, input().split())
	host.append(n)
	guest.append(m)
for i in host:
	c = guest.count(i)
	count += c
print(count)


c = 0
(a, b) = ([], [])
n = int(input())
for _ in range(n):
	i = input().split()
	a.append(i[0])
	b.append(i[1])
for x in a:
	c += b.count(x)
print(c)


c = [input().split() for i in range(int(input()))]
count = 0
for i in range(len(c)):
	for j in range(len(c)):
		if c[i][0] == c[j][1]:
			count += 1
print(count)


a = int(input())
x = []
x1 = 0
for i in range(a):
	(v, b) = input().strip().split(' ')
	(v, b) = [int(v), int(b)]
	x.append([v, b])
for i in range(a - 1):
	for j in range(i + 1, a):
		if x[i][0] == x[j][1]:
			x1 += 1
		if x[i][1] == x[j][0]:
			x1 += 1
print(x1)


n = int(input())
nums = []
for x in range(0, n):
	(a, b) = map(int, input().split())
	nums.append([a, b])
count = 0
for p in range(0, n):
	for q in range(0, n):
		if p != q:
			if nums[p][0] == nums[q][1]:
				count += 1
print(count)


n = int(input())
hh = []
aa = []
for i in range(n):
	(h, a) = input().split()
	hh.append(h)
	aa.append(a)
count = 0
for i in hh:
	for j in aa:
		if i == j:
			count += 1
print(count)


def solve(a, b, n):
	count = 0
	for i in range(n):
		for j in range(n):
			if i != j and a[i] == b[j]:
				count += 1
	return count
n = int(input())
a = []
b = []
for i in range(n):
	l = list(map(int, input().strip().split()))
	a.append(l[0])
	b.append(l[1])
result = solve(a, b, n)
print(result)


ans = 0
n = int(input())
a = []
h = []
for j in range(n):
	line = [int(i) for i in input().split()]
	h.append(line[0])
	a.append(line[1])
for i in range(n):
	for j in range(n):
		if i != j and h[i] == a[j]:
			ans += 1
print(str(ans))


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


n = int(input())
l = []
c = 0
for i in range(n):
	new = list(map(int, input().strip().split()))
	l.append(new)
for i in range(n - 1):
	f1 = l[i][0]
	f2 = l[i][1]
	for j in range(i, n - 1):
		if f1 == l[j + 1][1]:
			c += 1
	for j in range(i, n - 1):
		if f2 == l[j + 1][0]:
			c += 1
print(c)


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


n = int(input())
(l1, l2) = ([0] * n, [0] * n)
for i in range(n):
	(l1[i], l2[i]) = list(map(int, input().split(' ')))
print(sum((1 if l1[x] == l2[y] else 0 for x in range(n) for y in range(n))))


n = int(input())
team_uniform = []
for i in range(n):
	team_uniform.append([int(x) for x in input().split(' ')])
count = 0
for x in team_uniform:
	for y in team_uniform:
		if x[0] == y[1]:
			count += 1
print(count)


from itertools import permutations
n = int(input())
d = {n: input().split() for n in range(n)}
print(len([1 for (t1, t2) in permutations(list(range(n)), 2) if d[t1][0] == d[t2][1]]))


team = int(input())
hostList = []
guestList = []
for i in range(0, team):
	colorLine = input()
	colorList = colorLine.split(' ')
	hostList.append(int(colorList[0]))
	guestList.append(int(colorList[1]))
flip = 0
for j in range(0, team):
	for k in range(0, team):
		if hostList[j] == guestList[k] and j != k:
			flip += 1
print(flip)


n = int(input())
list = []
ti = 0
for i in range(0, n):
	(x, y) = map(int, input().split())
	l = [[x, y]]
	list.extend(l)
for i in range(0, len(list)):
	for w in range(0, len(list)):
		if w != i:
			if list[i][0] == list[w][1]:
				ti += 1
print(ti)


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


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


all_team_uniform_color = []
individual_team_uniform_color_input = []
total_team = int(input())
result = 0
for i in range(0, total_team):
	individual_team_uniform_color_input = list(map(int, input().split()))
	all_team_uniform_color.append(individual_team_uniform_color_input)
for i in range(0, total_team):
	for j in range(i + 1, total_team):
		if all_team_uniform_color[i][0] == all_team_uniform_color[j][1]:
			result = result + 1
		if all_team_uniform_color[i][1] == all_team_uniform_color[j][0]:
			result = result + 1
		else:
			continue
print(result)


n = int(input())
(h_l, g_l) = (list(), list())
ans = 0
for i in range(n):
	(h, g) = [int(s) for s in input().split()]
	h_l.append(h)
	g_l.append(g)
for hom in h_l:
	for gue in g_l:
		if hom == gue:
			ans += 1
print(ans)


n = int(input())
domsp = []
nedomsp = []
count = 0
for a in range(n):
	(dom, nedom) = map(int, input().split())
	domsp += [dom]
	nedomsp += [nedom]
for i in range(n):
	for j in range(n):
		if nedomsp[i] == domsp[j]:
			count += 1
print(count)


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


n = int(input())
k = []
for x in range(n):
	k += input().split()
print(sum((k[1::2].count(x) for x in k[::2])))


t = int(input())
f = []
s = []
c = 0
for i in range(t):
	(a, b) = list(map(int, input().split()))
	f.append(a)
	s.append(b)
	for i in f:
		if i == b:
			c += 1
	for i in s:
		if i == a:
			c += 1
print(c)


n = int(input())
if n == 1:
	print(0)
else:
	games = []
	ans = 0
	for i in range(n):
		a = list(map(int, input().split(' ')))
		games.append(a)
	for i in range(len(games)):
		cur = games[i]
		for j in range(i + 1, len(games)):
			if cur[0] == games[j][1]:
				ans += 1
			if cur[1] == games[j][0]:
				ans += 1
	print(ans)


n = int(input())
h = []
g = []
for i in range(n):
	(a, b) = map(int, input().split())
	h.append(a)
	g.append(b)
cnt = 0
for clr in h:
	cnt += g.count(clr)
print(cnt)


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


n = int(input())
h = []
a = []
s = 0
for i in range(n):
	color = input().split()
	h.append(color[0])
	a.append(color[1])
for j in range(n):
	for k in range(n):
		if h[j] == a[k]:
			s = s + 1
print(s)


n = int(input())
arr = [[0, 0] for i in range(n)]
for i in range(n):
	arr[i] = [int(j) for j in input().split()]
count = 0
for j in range(n):
	for i in range(n):
		if i == j:
			continue
		if arr[j][0] == arr[i][1]:
			count += 1
print(count)


n = int(input())
a = []
z = 0
x = 1
c = 0
m = 0
for i in range(n):
	a2 = input().split()
	a.append(a2)
for i in range(n):
	n = i
	if n > 0:
		if a[i - n][z] == a[i][x]:
			c += 1
		if a[i - n][x] == a[i][z]:
			c += 1
	for i in range(m + 1, n):
		if a[i - n][z] == a[i][x]:
			c += 1
		if a[i - n][x] == a[i][z]:
			c += 1
print(c)


num = int(input())
list1 = []
list2 = []
c = 0
for i in range(num):
	(a, b) = [int(j) for j in input().split(' ')]
	list1.append(a)
	list2.append(b)
for i in range(0, num):
	for j in range(0, num):
		if list1[j] == list2[i]:
			c += 1
print(c)


home = []
guest = []
ans = 0
for i in range(int(input())):
	(x, y) = input().split()
	home.append(int(x))
	guest.append(int(y))
for i in home:
	if i in guest:
		ans = ans + guest.count(i)
print(ans)


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


n = int(input())
r = []
z = []
t = 0
for i in range(n):
	l = list(map(int, input().strip().split()))
	r.append(l[0])
	z.append(l[1])
for i in r:
	for x in z:
		if i == x:
			t += 1
print(t)


from collections import Counter
n = int(input())
h_t = []
a_t = []
for i in range(n):
	(h, a) = [int(j) for j in input().split()]
	h_t.append(h)
	a_t.append(a)
h_x = Counter(h_t)
a_x = Counter(a_t)
ans = 0
for i in h_x.keys():
	if i in a_x.keys():
		ans = ans + h_x[i] * a_x[i]
print(ans)


n = int(input())
a = []
h = []
tot = n * (n - 1)
count = 0
for i in range(0, n):
	(a_i, h_i) = map(int, input().split())
	a.append(a_i)
	h.append(h_i)
for i in range(0, len(a)):
	for j in range(0, len(h)):
		if a[i] == h[j]:
			count += 1
print(count)


n = int(input())
a = []
b = []
x = ''
y = ''
for i in range(n):
	(x, y) = map(int, input().split())
	a.append(x)
	b.append(y)
print(sum((a.count(i) * b.count(i) for i in set(a))))


from sys import stdin
N = stdin.readline()
n = []
m = []
for i in range(int(N)):
	(a, b) = [int(x) for x in stdin.readline().split()]
	n.append(int(a))
	m.append(int(b))
ans = 0
for i in range(int(N)):
	for j in range(int(N)):
		if i != j and n[i] == m[j]:
			ans += 1
print(ans)


n = int(input())
a_home = []
a_otside = []
count = 0
for i in range(n):
	(n_home, n_outside) = map(int, input().split())
	a_home.append(n_home)
	a_otside.append(n_outside)
for i in range(len(a_home)):
	count += a_otside.count(a_home[i])
print(count)


a = []
for _ in range(int(input())):
	a.append(list(map(int, input().strip().split())))
(h, g) = ([], [])
for i in a:
	h.append(i[0])
	g.append(i[1])
count = 0
for i in h:
	if i in g:
		count += g.count(i)
print(count)


n = int(input())
l1 = []
l2 = []
for i in range(n):
	(p, q) = map(int, input().split())
	l1.append(p)
	l2.append(q)
sum = 0
for i in l1:
	for j in l2:
		if i == j:
			sum = sum + 1
print(sum)


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))


(number, a, ans) = (int(input()), [], 0)
for i in range(number):
	a.append([int(j) for j in input().split()])
for i in range(number):
	for b in range(number):
		if i == b:
			continue
		if a[i][0] == a[b][1]:
			ans += 1
print(ans)


import sys
t = int(input())
a = []
b = []
ans = 0
for i in range(0, t):
	(c, d) = map(int, input().split())
	a.append(c)
	b.append(d)
for i in range(0, t):
	for j in range(0, t):
		if a[i] == b[j]:
			ans += 1
print(ans)


n = int(input())
ar = []
for _ in range(n):
	(h, a) = [int(i) for i in input().split()]
	ar.append(h)
	ar.append(a)
l = len(ar)
c = 0
for i in range(0, l, 2):
	for j in range(1, l, 2):
		if ar[i] == ar[j]:
			c += 1
print(c)


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


n = int(input())
h = []
a = []
for i in range(n):
	(hh, aa) = [int(i) for i in input().split()]
	h.append(hh)
	a.append(aa)
cnt = 0
for i in h:
	cnt += a.count(i)
print(cnt)


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


n = int(input())
home = []
guest = []
matches = 0
for j in range(n):
	(m, a) = map(int, input().split())
	home.append(m)
	guest.append(a)
sethome = set(home)
for i in sethome:
	matches += guest.count(i) * home.count(i)
print(matches)


def games():
	num_of_teams = int(input())
	hj = []
	gj = {}
	for i in range(num_of_teams):
		jersey = [int(j) for j in input().split(' ')]
		hj.append(jersey[0])
		if jersey[1] in gj:
			gj[jersey[1]] += 1
		else:
			gj[jersey[1]] = 1
	total = 0
	for color in hj:
		if color in gj:
			total += gj[color]
	return total
print(games())


n = int(input())
lis1 = [0] * n
lis2 = [0] * n
for i in range(n):
	(lis1[i], lis2[i]) = map(int, input().split())
count = 0
for item in lis1:
	for i in range(n):
		if lis2[i] == item:
			count += 1
print(count)


l1 = []
l2 = []
n = int(input())
for i in range(n):
	p = 0
	l = list(map(int, input().split()))
	for i in l:
		if p == 0:
			l1.append(i)
			p += 1
		else:
			l2.append(i)
co = 0
for i in l1:
	for j in l2:
		if i == j:
			co += 1
print(co)


N = int(input())
Teams = [[0] * 2] * N
noofgames = 0
for i in range(N):
	Teams[i] = input().split()
host_player = []
guest_player = []
for i in range(N):
	host_player = Teams[i]
	for j in range(N):
		if j != i:
			guest_player = Teams[j]
			if host_player[0] == guest_player[1]:
				noofgames += 1
print(noofgames)


n = int(input())
a = []
b = []
k = 0
for i in range(n):
	(x, y) = [int(i) for i in input().split()]
	a = a + [x]
	b = b + [y]
for i in a:
	if i in b:
		k = k + b.count(i)
print(k)


x = int(input())
chet = 0
list = []
for i in range(0, x):
	list.append(input().split())
for i in range(0, len(list)):
	list[i][0] = int(list[i][0])
	list[i][1] = int(list[i][1])
for i in range(0, len(list)):
	for b in range(0, len(list)):
		if b == i:
			continue
		elif list[i][0] == list[b][1]:
			chet += 1
print(chet)


n = int(input())
(e, c, res) = ({}, {}, 0)
for i in range(n):
	(a, b) = map(int, input().split())
	if a not in e:
		e[a] = 1
	else:
		e[a] = e.get(a) + 1
	if b not in c:
		c[b] = 1
	else:
		c[b] = c.get(b) + 1
if len(e) >= len(c):
	m = list(c.keys())
else:
	m = list(e.keys())
for j in m:
	if e.get(j) != None and c.get(j) != None:
		res = res + c[j] * e[j]
print(res)


n = int(input())
uniforms = [list(map(int, input().split())) for i in range(n)]
total = 0
for i in range(n):
	for j in range(n):
		if j == i:
			continue
		if uniforms[i][0] == uniforms[j][1]:
			total += 1
print(total)


n = int(input())
p = 0
b = []
c = []
for i in range(n):
	(h, g) = map(int, input().split())
	b.append(h)
	c.append(g)
for i in range(len(b)):
	for j in range(len(c)):
		if b[i] == c[j] and i != j:
			p += 1
		else:
			pass
print(p)


n = int(input())
teams = []
for i in range(0, n):
	teams.append([int(x) for x in input().split()])
score = 0
p = list(reversed(teams))
for j in range(0, len(teams)):
	for k in range(j + 1, len(teams)):
		if teams[j][0] == teams[k][1]:
			score += 1
		if p[j][0] == p[k][1]:
			score += 1
print(score)


def kits(n):
	teams = list(range(len(n)))
	result = 0
	for i in range(len(teams)):
		j = i
		while j < len(teams):
			if colors[i][0] == colors[j][1]:
				result += 1
			if colors[j][0] == colors[i][1]:
				result += 1
			j += 1
	return result
n = input()
colors = {}
for i in range(int(n)):
	colors[i] = input().split()
print(kits(colors))


home = {}
guest = {}
for _ in range(int(input())):
	i = input().split()
	(h, g) = (i[0], i[1])
	home[h] = home[h] + 1 if h in home else 1
	guest[g] = 1 + guest[g] if g in guest else 1
count = 0
for i in home:
	if i in guest:
		count += guest[i] * home[i]
print(count)


c = int(input())
j = 0
e = []
d = []
for i in range(0, c):
	a = [int(x) for x in input().split()]
	e += [int(a[1])]
	d += [int(a[0])]
i = 0
k = 0
while i < len(d):
	j = 0
	while j < len(e):
		if d[i] == e[j]:
			k += 1
			j += 1
		else:
			j += 1
	i += 1
print(k)


teams = [input().split(' ') for i in range(int(input()))]
home = [i[0] for i in teams]
guest = [i[1] for i in teams]
times = 0
for i in range(len(home) - 1):
	if home[i] in guest[i + 1:]:
		times += guest[i + 1:].count(home[i])
	if guest[i] in home[i + 1:]:
		times += home[i + 1:].count(guest[i])
print(times)


from collections import defaultdict
x = int(input())
mHome = defaultdict(int)
mAway = defaultdict(int)
for i in range(0, x):
	(a, b) = map(int, input().split())
	mHome[a] += 1
	mAway[b] += 1
sum: int = 0
for i in mAway:
	sum += mHome[i] * mAway[i]
print(sum)


def main():

	def finding_frist_occurrence(l, target, s, e, result=None):
		if s > e:
			return result
		mid = (s + e) // 2
		if target < l[mid]:
			return finding_frist_occurrence(l, target, s, mid - 1, result)
		elif target == l[mid]:
			return finding_frist_occurrence(l, target, s, mid - 1, mid)
		else:
			return finding_frist_occurrence(l, target, mid + 1, e, result)

	def finding_last_occurrence(l, target, s, e, result=None):
		if s > e:
			return result
		mid = (s + e) // 2
		if target > l[mid]:
			return finding_last_occurrence(l, target, mid + 1, e, result)
		elif target == l[mid]:
			return finding_last_occurrence(l, target, mid + 1, e, mid)
		else:
			return finding_last_occurrence(l, target, s, mid - 1, result)

	def count_accurrence(l, target):
		start = finding_frist_occurrence(l, target, 0, len(l) - 1)
		if start is not None:
			end = finding_last_occurrence(l, target, 0, len(l) - 1)
			return end - start + 1
		return 0
	nteams = int(input())
	home_uniforms = []
	guest_uniforms = []
	for i in range(nteams):
		t = tuple(map(int, input().split()))
		home_uniforms.append(t[0])
		guest_uniforms.append(t[1])

	def games(home_uniforms, guest_uniforms):
		guest_uniforms.sort()
		counter = 0
		for home_uniform in home_uniforms:
			counter += count_accurrence(guest_uniforms, home_uniform)
		return counter
	print(games(home_uniforms, guest_uniforms))
main()


n = int(input())
host = []
guest = []
while n > 0:
	inp = input().split()
	host.append(int(inp[0]))
	guest.append(int(inp[1]))
	n -= 1
c = 0
for i in host:
	c += guest.count(i)
print(c)


def Games(n, uniformColors):
	transposedList = list(map(list, zip(*uniformColors)))
	result = 0
	for hostUniform in transposedList[0]:
		for guestUniform in transposedList[1]:
			if hostUniform == guestUniform:
				result += 1
	return result
n = int(input())
uniformColors = []
temp = 0
while temp < n:
	(x, y) = input().split()
	uniformColors.append([int(x), int(y)])
	temp += 1
print(Games(n, uniformColors))


n = int(input())
ListOfHomeColors = []
ListOfAwayColors = []
Final_counter = 0
for a in range(n):
	colors = input().split()
	ListOfHomeColors.append(colors[0])
	ListOfAwayColors.append(colors[1])
for a in ListOfHomeColors:
	x = ListOfAwayColors.count(a)
	Final_counter += x
print(Final_counter)


a = []
b = []
for k in range(int(input())):
	t = list(map(int, input().split()))
	a.append(t[0])
	b.append(t[1])
p = 0
for i in range(len(a)):
	if a[i] in b:
		p += b.count(a[i])
print(p)


m = []
f = []
n = int(input())
count = 0
for N in range(n):
	(h, g) = list(map(int, input().split()))
	m.append(h)
	f.append(g)
for i in range(n):
	for j in range(n):
		if m[i] == f[j]:
			count += 1
print(count)


teams = int(input())
dictionaryOfHomeColors = {}
dictionaryOfAwayColors = {}
for i in range(teams):
	colors = input().split()
	dictionaryOfHomeColors[colors[0]] = dictionaryOfHomeColors.get(colors[0], 0) + 1
	dictionaryOfAwayColors[colors[1]] = dictionaryOfAwayColors.get(colors[1], 0) + 1
hostWearingAway = 0
for entry in dictionaryOfHomeColors:
	hostWearingAway += dictionaryOfHomeColors.get(entry) * dictionaryOfAwayColors.get(entry, 0)
print(hostWearingAway)


n = int(input())
games = {}
key_list = []
value_list = []
for i in range(n):
	(a, b) = input().split()
	key_list.append(a)
	value_list.append(b)
count = 0
for keys in key_list:
	for values in value_list:
		if keys == values:
			count += 1
print(count)


n = int(input())
lista = []
resposta = 0
while len(lista) < n:
	time = input()
	answr = {'casa': time.split(' ')[0], 'fora': time.split(' ')[1]}
	lista.append(answr)
for time0 in range(len(lista)):
	for time1 in range(len(lista)):
		if lista[time0]['casa'] == lista[time1]['fora']:
			resposta += 1
print(resposta)


(a, b, c) = ([], [], 0)
n = int(input())
for _ in range(n):
	(x, y) = [int(x) for x in input().split()]
	a.append(x)
	b.append(y)
for e in a:
	for i in range(n):
		if e == b[i]:
			c += 1
print(c)


def main():
	n = int(input())
	h = []
	a = []
	for i in range(n):
		(hi, ai) = map(int, input().split(' '))
		h.append(hi)
		a.append(ai)
	ans = 0
	for i in range(n):
		for j in range(n):
			if i == j:
				continue
			if a[i] == h[j]:
				ans += 1
	return ans
print(main())


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


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


from collections import defaultdict
r = int(input())
h = defaultdict(int)
g = defaultdict(int)
l = []
for i in range(r):
	(a, b) = map(int, input().split())
	h[a] += 1
	g[b] += 1
c = 0
for i in h:
	if i in g:
		c += h[i] * g[i]
print(c)


n = int(input())
a = []
a_domach = []
a_gost = []
count = 0
for i in range(n):
	a.append(list(input().split()))
for j in range(1):
	for i in range(n):
		a_domach.append(a[i][j])
for j in range(1, 2):
	for i in range(n):
		a_gost.append(a[i][j])
for ii in a_domach:
	for jj in a_gost:
		aa = a_domach.index(ii)
		bb = a_gost.index(jj)
		cc = a_domach[a_domach.index(ii)]
		dd = a_gost[a_gost.index(jj)]
		if a_domach.index(ii) != a_gost.index(jj) and ii == jj:
			count += 1
print(count)


count = 0
lista = []
listb = []
n = int(input())
for _ in range(n):
	(a, b) = map(int, input().split())
	lista.append(a)
	listb.append(b)
for i in range(n):
	for j in range(n):
		if listb[i] == lista[j]:
			count += 1
print(count)


teams = int(input())
uniform = []
count = 0
for _ in range(teams):
	uniform.append(list(map(lambda x: int(x), input().split(' '))))
home_team = -1
for h_team in uniform:
	home_team = h_team[0]
	for v_team in uniform:
		if home_team != v_team[0] and v_team[1] == home_team:
			count += 1
print(count)


from collections import defaultdict
n = int(input())
uniforms = []
for i in range(n):
	uniforms.append(list(map(int, input().split())))
home_jerseys2freq = defaultdict(int)
for i in range(n):
	home_jersey = uniforms[i][0]
	home_jerseys2freq[home_jersey] += 1
num_games = 0
for i in range(n):
	away_jersey = uniforms[i][1]
	if away_jersey in home_jerseys2freq:
		num_games += home_jerseys2freq[away_jersey]
print(num_games)


import sys
import math
import bisect

def main():
	n = int(input())
	A = []
	for i in range(n):
		A.append(list(map(int, input().split())))
	ans = 0
	for i in range(n):
		for j in range(n):
			if i == j:
				continue
			if A[i][0] == A[j][1]:
				ans += 1
	print(ans)
main()


n = int(input())
A = []
B = []
for i in range(n):
	(a, b) = map(int, input().split())
	A = A + [a]
	B = B + [b]
c = 0
for i in A:
	for j in B:
		if i == j:
			c = c + 1
print(c)


n = int(input())
s = [tuple(map(int, input().split(' '))) for i in range(n)]
ans = 0
for i in range(n):
	for j in range(n):
		if i != j and s[i][0] == s[j][1]:
			ans += 1
print(ans)


n = int(input())
o = []
e = []
c = 0
for i in range(n):
	x = [int(x) for x in input().split()]
	o.append(x[0])
	e.append(x[1])
for i in range(n):
	for j in range(n):
		if o[i] == e[j]:
			c += 1
print(c)


array = []
for i in range(int(input())):
	x = [[int(i) for i in input().split()]]
	array += x
tot = 0
for i in range(len(array)):
	for j in range(len(array)):
		if array[i][0] == array[j][1]:
			tot += 1
print(tot)


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


num = int(input())
h = []
a = []
count = 0
for _ in range(num):
	(ho, aw) = input().split()
	h.append(int(ho))
	a.append(int(aw))
for _ in range(num):
	for i in range(num):
		if h[_] == a[i]:
			count += 1
print(count)


n = int(input())
store = []
for i in range(n):
	(x, y) = input().split()
	store.append([x, y])
gUniform = 0
for i in range(n):
	for j in range(i + 1, n):
		if store[i][0] == store[j][1] or store[i][1] == store[j][0]:
			gUniform += 1
		if store[i][0] == store[j][1] and store[i][1] == store[j][0]:
			gUniform += 1
print(gUniform)


n = int(input())
A = []
B = []
confliction = 0
for i in range(n):
	(a, b) = map(int, input().split())
	A.append(a)
	B.append(b)
for i in A:
	confliction += B.count(i)
print(confliction)


num = int(input())
host = []
guest = []
Ans = 0
for i in range(num):
	(h, g) = map(int, input().split())
	host.append(h)
	guest.append(g)
for i in range(len(host)):
	for j in range(len(guest)):
		if host[i] == guest[j]:
			Ans += 1
print(Ans)


n = int(input())
(inp1, inp2) = ([], [])
for i in range(n):
	inp = input().split(' ')
	inp1.append(int(inp[0]))
	inp2.append(int(inp[1]))
same = [i for i in inp1 if i in inp2]
result = 0
same.sort()
inp2.sort()
while True:
	try:
		if len(inp1) == 0:
			break
		c = same.count(same[0])
		result += c * inp2.count(same[0])
		same = same[c:]
	except:
		print(result)
		exit()


n = int(input())
d = [0] * n
v = [0] * n
count = 0
for i in range(n):
	(a, b) = input().split()
	(a, b) = (int(a), int(b))
	d[i] = a
	v[i] = b
for i in range(n):
	for k in range(n):
		if d[i] == v[k]:
			count += 1
print(count)


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


home = dict()
away = dict()
count = 0
for _ in range(int(input())):
	(h, a) = tuple(map(int, input().split()))
	home[h] = home.get(h, 0) + 1
	away[a] = away.get(a, 0) + 1
for i in home.keys():
	count += home[i] * away.get(i, 0)
print(count)


teams = int(input())
homes = []
guests = []
for team in range(teams):
	(home, guest) = input().split(' ')
	homes.append(home)
	guests.append(guest)
counter = 0
for home in homes:
	for guest in guests:
		if home == guest:
			counter += 1
print(counter)


lysts = [input().split() for i in range(int(input()))]
count = 0
for i in lysts:
	for j in lysts:
		if i[0] == j[1]:
			count += 1
print(count)


class CodeforcesTask268ASolution:

	def __init__(self):
		self.result = ''
		self.n = 0
		self.teams = []

	def read_input(self):
		self.n = int(input())
		for x in range(self.n):
			self.teams.append([int(y) for y in input().split(' ')])

	def process_task(self):
		hosts = [x[0] for x in self.teams]
		guests = [x[1] for x in self.teams]
		times = 0
		for ho in hosts:
			times += guests.count(ho)
		self.result = str(times)

	def get_result(self):
		return self.result
Solution = CodeforcesTask268ASolution()
Solution.read_input()
Solution.process_task()
print(Solution.get_result())


lst = []
n = int(input())
for i in range(n):
	lst.append([int(i) for i in input().split()])
match = 0
for i in range(n):
	for j in range(i + 1, n):
		if lst[i][0] == lst[j][1]:
			match += 1
		if lst[i][1] == lst[j][0]:
			match += 1
print(match)


n = int(input())
h = []
g = []
for i in range(n):
	(a, b) = map(int, input().split(' '))
	h.append(a)
	g.append(b)
resp = 0
for i in range(n):
	for j in range(n):
		if i == j or h[i] != g[j]:
			continue
		resp += 1
print(resp)


n = int(input())
home_color = []
guest_color = []
for _ in range(n):
	(a, b) = map(int, input().split())
	home_color.append(a)
	guest_color.append(b)
count = 0
for color in home_color:
	count += guest_color.count(color)
print(count)


def main():
	L = []
	Elem = []
	d = 0
	n = int(input())
	for i in range(n):
		Elem = list(map(int, input().split()))
		L.append(Elem)
	for i in range(n):
		for j in range(n):
			if L[i][0] == L[j][1]:
				d += 1
	print(d)
main()


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


n = input()
n = int(n)
h = []
a = []
count = 0
for i in range(0, n):
	(b, c) = input().split()
	h.append(b)
	a.append(c)
for i in range(0, len(h)):
	for j in range(0, len(a)):
		if h[i] == a[j] and i != j:
			count = count + 1
print(count)


def main():
	n = int(input())
	teams = []
	rez = 0
	while n > 0:
		n -= 1
		teams.append(input().split(' '))
	for host in teams:
		for guest in teams:
			if host[0] == guest[1]:
				rez += 1
	print(rez)
main()


n = int(input())
A = []
k = 0
for i in range(n):
	A.append(input().split())
A1 = A.copy()
for i in range(n):
	B = A.pop(i)
	for j in range(n - 1):
		if B[0] == A[j][1]:
			k = k + 1
	A.clear()
	A = A1.copy()
print(k)


from sys import stdin, stdout
from math import ceil, floor
from collections import deque
inp = stdin.readline
out = stdout.write
n = int(inp().strip())
l = []
for i in range(n):
	(h, g) = map(int, inp().strip().split())
	l.append([h, g])
c = 0
for i in range(n):
	for j in range(n):
		if l[i][0] == l[j][1]:
			c += 1
out(str(c))


N = int(input())
host = {}
guest = {}
for i in range(N):
	(temp0, temp1) = map(int, input().split())
	if temp0 in host:
		host[temp0] += 1
	else:
		host[temp0] = 1
	if temp1 in guest:
		guest[temp1] += 1
	else:
		guest[temp1] = 1
count = 0
for i in host:
	if i in guest:
		count += host[i] * guest[i]
print(count)


n = int(input())
home_col = list()
guest_col = list()
count = 0
for i in range(n):
	team = [int(x) for x in input().split()]
	home_col.append(team[0])
	guest_col.append(team[1])
for i in range(n):
	for i2 in range(n):
		if home_col[i] == guest_col[i2] and i != i2:
			count += 1
print(count)


import math
size = int(input())
arrHome = {}
arrGuest = {}
totCount = 0
for i in range(size):
	(h, a) = [int(x) for x in input().split()]
	totCount += arrGuest.get(h, 0)
	totCount += arrHome.get(a, 0)
	if arrHome.get(h, 0) == 0:
		arrHome[h] = 1
	else:
		arrHome[h] = arrHome[h] + 1
	if arrGuest.get(a, 0) == 0:
		arrGuest[a] = 1
	else:
		arrGuest[a] = arrGuest[a] + 1
print(totCount)


n = int(input())
l = []
c = 0
for i in range(n):
	s = str(input()).split()
	l.append([int(s[0]), int(s[1])])
	s = []
for i in range(n):
	for j in range(n):
		if (i != j) & (l[i][0] == l[j][1]):
			c += 1
print(c)


n = int(input())
home = []
away = []
for i in range(n):
	(h, a) = input().split()
	home.append(h)
	away.append(a)
print(sum([away.count(e) for e in home]))


n = int(input())
x = []
for i in range(n):
	z = list(input().split())
	x.append(z)
cnt = 0
for i in x:
	a = i[0]
	for j in range(len(x)):
		if x[j][1] == a:
			cnt += 1
print(cnt)


n = int(input())
x = []
for i in range(n):
	x.append(input().split(' '))
X = []
Y = []
for i in x:
	X.append(int(i[0]))
for i in x:
	Y.append(int(i[1]))
c = 0
for i in X:
	for j in Y:
		if i == j:
			c += 1
print(c)


import math
from collections import defaultdict, Counter, deque
INF = float('inf')

def gcd(a, b):
	while b:
		(a, b) = (b, a % b)
	return a

def isPrime(n):
	if n <= 1:
		return False
	i = 2
	while i ** 2 <= n:
		if n % i == 0:
			return False
		i += 1
	return True

def primeFactor(n):
	if n % 2 == 0:
		return 2
	i = 3
	while i ** 2 <= n:
		if n % i == 0:
			return i
		i += 1
	return n

def vars():
	return map(int, input().split())

def array():
	return list(map(int, input().split()))

def main():
	n = int(input())
	ti = []
	for i in range(n):
		(h, a) = vars()
		ti.append((h, a))
	cnt = 0
	for i in range(n):
		for j in range(n):
			if i != j:
				if ti[i][0] == ti[j][1]:
					cnt += 1
	print(cnt)
t = 1
for _ in range(t):
	main()


n = int(input())
guest = []
home = []
for i in range(n):
	a = list(map(int, input().split()))
	guest.append(a[1])
	home.append(a[0])
count = 0
for i in range(n):
	for j in range(i + 1, n):
		if guest[i] == home[j] and home[i] == guest[j]:
			count += 2
		elif guest[i] == home[j] or home[i] == guest[j]:
			count += 1
print(count)


def games(l):
	changes = 0
	for i in range(len(l) - 1):
		for j in range(i + 1, len(l)):
			if l[i][0] == l[j][1]:
				changes += 1
			if l[i][1] == l[j][0]:
				changes += 1
	return changes
n = int(input().strip())
l = list()
for i in range(n):
	l.append(list(map(int, input().strip().split())))
print(games(l))


from collections import Counter
n = int(input())
first_array = []
second_array = []
for i in range(0, n):
	line = input().split()
	first_element = int(line[0])
	second_element = int(line[1])
	first_array.append(first_element)
	second_array.append(second_element)
counter = 0
first_counter = Counter(first_array)
for i in second_array:
	counter += first_counter[i]
print(counter)


n = int(input())
x = []
s = 0
for i in range(n):
	temp = input().split()
	x += [temp]
for i in x:
	for j in x:
		if i[0] == j[1]:
			s += 1
print(s)


n = int(input())
h = []
g = []
out = 0
for i in range(n):
	a = [int(j) for j in input().split()]
	h.append(a[0])
	g.append(a[1])
for m in h:
	for n in g:
		if m == n:
			out += 1
print(out)


(n, res, count) = (int(input()), [], 0)
for i in range(n):
	res.append(input().split())
res1 = [i[0] for i in res]
res2 = [i[1] for i in res]
for i in range(n):
	for j in range(n):
		if res2[j] == res1[i]:
			count += 1
print(count)


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


GameNum = int(input())
TeamsUniform = []
count = 0
while GameNum:
	inp = list(map(int, input().split(' ')))
	TeamsUniform.append(inp)
	GameNum = GameNum - 1
for team1 in TeamsUniform:
	for team2 in TeamsUniform:
		if team2[0] == team1[1]:
			count = count + 1
print(count)


n = int(input())
v = []
d = 0
for i in range(n):
	(x, y) = map(int, input().split())
	s = [x, y]
	v.append(s)
for i in range(n):
	for j in range(i + 1, n):
		if v[i][0] == v[j][1]:
			d += 1
		if v[i][1] == v[j][0]:
			d += 1
print(d)


import sys
from functools import reduce
from collections import Counter
import time
import datetime
import math

def ip():
	return int(sys.stdin.readline())

def sip():
	return input()

def mip():
	return map(int, sys.stdin.readline().split())

def mips():
	return map(str, sys.stdin.readline().split())

def lip():
	return list(map(int, sys.stdin.readline().split()))

def matip(n, m):
	lst = []
	for i in range(n):
		arr = lip()
		lst.insert(i, arr)
	return lst

def factors(n):
	return list(set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0))))

def minJumps(arr, n):
	jumps = [0 for i in range(n)]
	if n == 0 or arr[0] == 0:
		return float('inf')
	jumps[0] = 0
	for i in range(1, n):
		jumps[i] = float('inf')
		for j in range(i):
			if i <= j + arr[j] and jumps[j] != float('inf'):
				jumps[i] = min(jumps[i], jumps[j] + 1)
				break
	return jumps[n - 1]

def dic(arr):
	return Counter(arr)

def check_prime(n):
	if n < 2:
		return False
	for i in range(2, int(n ** 0.5) + 1, 2):
		if n % i == 0:
			return False
	return True
n = ip()
lst = []
for i in range(n):
	h = lip()
	lst.append(h)
count = 0
for i in range(n):
	for j in range(n):
		if i != j and lst[i][0] == lst[j][1]:
			count += 1
print(count)


from sys import stdin
n = int(stdin.readline())
(h, g) = ([], [])
for i in range(n):
	(x, y) = map(int, stdin.readline()[:-1].split(' '))
	h += [x]
	g += [y]
print(sum([g.count(i) for i in h]))


n = int(input())
a = []
b = []
for i in range(n):
	(aa, bb) = [int(x) for x in input().split()]
	a.append(aa)
	b.append(bb)
c = 0
for i in b:
	if i in a:
		c += a.count(i)
print(c)


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


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


num = int(input())
line = []
for i in range(num):
	line.append(input().split(' '))
summ = 0
for i in range(num):
	for j in range(num):
		if line[i][0] == line[j][1]:
			summ += 1
print(summ)


n = input()
n = int(n)
home = []
away = []
for i in range(0, n):
	line = input()
	line = line.split()
	h = line[0]
	h = int(h)
	home.append(h)
	a = line[1]
	a = int(a)
	away.append(a)
clash = 0
for i in range(0, n):
	for j in range(0, n):
		if i == j:
			continue
		if home[i] == away[j]:
			clash = clash + 1
print(clash)


n = int(input())
homej = []
awayj = []
for _ in range(n):
	x = list(map(int, input().split()))
	home = x[0]
	away = x[1]
	homej.append(home)
	awayj.append(away)
times = 0
for el in homej:
	for ell in awayj:
		if el == ell:
			times += 1
print(times)


n = int(input())
num = 0
lst = []
for i in range(n):
	ab = input().split()
	lst.append(ab)
for i in range(n):
	for it in range(n):
		if lst[i][0] == lst[it][1]:
			num += 1
print(num)


n = int(input())
home = dict()
away = dict()
count = 0
while n != 0:
	n -= 1
	(h, a) = map(int, input().strip().split())
	home[h] = home.get(h, 0) + 1
	away[a] = away.get(a, 0) + 1
for (k, v) in home.items():
	for (k1, v1) in away.items():
		if k1 == k:
			count += v * v1
print(count)


n = int(input())
host = []
guest = []
for i in range(n):
	x = [int(k) for k in input().split()]
	host.append(x[0])
	guest.append(x[1])
print(sum([guest.count(host[i]) for i in range(n)]))


n = int(input())
m = 0
a = []
b = []
y = 0
while m < n:
	i = [int(x) for x in input().split()]
	a.append(i[0])
	b.append(i[1])
	m = m + 1
m = 0
while m < n:
	y = y + a.count(b[m])
	m = m + 1
print(y)


n = int(input())
l = []
result = 0
for i in range(n):
	(a, b) = [int(j) for j in input().split()]
	l.append((a, b))
for i in range(n):
	for j in range(n):
		if l[i][0] == l[j][1]:
			result += 1
print(result)


n = int(input())
c = n
result = 0
l = []
if 2 <= n <= 30:
	while c > 0:
		(hi, ai) = map(int, input().split())
		c -= 1
		if 0 <= hi <= 1000 and 0 <= ai <= 1000:
			l.append(hi)
			l.append(ai)
l_1 = []
l_2 = []
len = len(l)
while len > 0:
	l_1.append(l[0])
	l.pop(0)
	l_2.append(l[0])
	l.pop(0)
	len -= 2
for i in l_1:
	for j in l_2:
		if i == j:
			result += 1
print(result)


n = int(input())
h = {}
g = []
for i in range(n):
	temp = input().split(' ')
	if int(temp[0]) in h:
		h[int(temp[0])] += 1
	else:
		h[int(temp[0])] = 1
	g.append(temp[1])
count = 0
for i in g:
	if int(i) in h:
		count += h[int(i)]
print(count)


n = int(input())
ans = 0
h = []
g = []
for i in range(n):
	(h1, g1) = map(int, input().split())
	h.append(h1)
	g.append(g1)
for e1 in h:
	for e2 in g:
		if e1 == e2:
			ans += 1
print(ans)


iterNum = int(input())
homeAway = [0] * iterNum
guestShirtScore = 0
for i in range(iterNum):
	homeAway[i] = [i] + list(map(int, input().split()))
for i in range(len(homeAway)):
	indexVal = homeAway[i][0]
	homeVal = homeAway[i][1]
	for x in range(len(homeAway)):
		if homeAway[x][0] != indexVal:
			if homeAway[x][2] == homeVal:
				guestShirtScore += 1
print(guestShirtScore)


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


n = int(input())
home = []
away = {}
for _ in range(n):
	s = list(map(int, input().split()))
	home.append(s[0])
	if s[1] not in away:
		away[s[1]] = 1
	else:
		away[s[1]] += 1
res = 0
for i in home:
	if i in away:
		res += away[i]
print(res)


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


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


n = int(input())
z = []
k = []
num = 0
for i in range(n):
	(z1, k1) = [int(x) for x in input().split()]
	z.append(z1)
	k.append(k1)
for i in range(n):
	a = k[i]
	for j in range(n):
		if a != z[j]:
			continue
		else:
			num += 1
print(num)


n = int(input())
l = []
while n:
	l.append([int(x) for x in input().split()])
	n -= 1
(a, b) = ([], [])
for i in l:
	a.append(i[0])
	b.append(i[1])
c = 0
for i in a:
	for j in b:
		if i == j:
			c += 1
print(c)


noOfTeams = int(input())
teamsUniformsList = []
noOfGamesThatHostTeamWillPlayInGuestUniform = 0
for i in range(noOfTeams):
	teamsUniformsList.append(input())
for (index, value) in enumerate(teamsUniformsList):
	for i in range(len(teamsUniformsList)):
		if index != i:
			if int(value.split(' ')[0]) == int(teamsUniformsList[i].split(' ')[1]):
				noOfGamesThatHostTeamWillPlayInGuestUniform += 1
print(noOfGamesThatHostTeamWillPlayInGuestUniform)


n = int(input())
(a, b) = zip(*[input().split() for _ in range(n)])
count = 0
for x in a:
	for y in b:
		if x == y:
			count += 1
print(count)


def main():
	n = int(input())
	m = []
	count = 0
	for i in range(n):
		(a, b) = map(int, input().split())
		m.append([a, b])
		for j in range(i):
			if m[i][0] == m[j][1]:
				count += 1
			if m[j][0] == m[i][1]:
				count += 1
	print(count)
main()


n = int(input())
nOfGames = 0
uniforms = []
for i in range(n):
	uniform = tuple(map(int, input().split()))
	uniforms.append(uniform)
for host_team in uniforms:
	for guest_team in uniforms:
		if not host_team == guest_team:
			if host_team[0] == guest_team[1]:
				nOfGames += 1
print(nOfGames)


n = int(input())
perv = []
vtor = []
count = 0
for i in range(n):
	(h, a) = map(int, input().split())
	perv.append(h)
	vtor.append(a)
for i in range(n):
	if perv[i] in vtor:
		z = perv[i]
		for i in range(n):
			if vtor[i] == z:
				count += 1
print(count)


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


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


list1 = []
homelist = []
awaylist = []
sol = []
for item in range(int(input())):
	y = input().split()
	for a in y:
		list1.append(int(a))
list2 = list(enumerate(list1))
for (a, b) in list2:
	if a % 2 == 0:
		homelist.append(b)
	else:
		awaylist.append(b)
for p in homelist:
	for q in awaylist:
		if p == q:
			sol.append((p, q))
print(len(sol))


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


a = [list(map(int, input().split())) for i in range(int(input()))]
print(sum((1 for i in range(len(a)) for j in range(len(a)) if a[i][0] == a[j][1] and i != j)))


x = int(input())
l = []
p = []
for i in range(x):
	(y, z) = [int(a) for a in input().split()]
	l.append(y)
	p.append(z)
s = 0
for i in l:
	for j in p:
		if i == j:
			s += 1
print(s)


n = int(input())
homes = [0] * n
guests = [0] * n
for i in range(n):
	(homes[i], guests[i]) = list(map(int, input().strip().split(' ')))
ans = 0
for color in homes:
	ans += guests.count(color)
print(ans)


n = int(input())
l = []
for i in range(n):
	st = input()
	st = st.split()
	(st[0], st[1]) = (int(st[0]), int(st[1]))
	l.append(st)
count = 0
for i in range(n):
	for j in range(n):
		if l[i][0] == l[j][1]:
			count += 1
print(count)


n = int(input())
count = 0
colors = []
for i in range(n):
	l = input().split()
	for j in colors:
		count += (j[0] == l[1]) + (j[1] == l[0])
	colors.append(l)
print(count)


n = int(input())
d = []
for i in range(n):
	inputs = input().split(' ')
	d.append(inputs)
c = 0
for i in range(0, len(d)):
	for j in range(0, len(d)):
		if d[i][1] == d[j][0]:
			if d[i][0] == d[j][0]:
				pass
			else:
				c += 1
print(c)


n = int(input())
li = []
count = 0
for i in range(n):
	dl = list(map(int, input().split()))
	li.append(dl)
for i in range(n):
	for j in range(n):
		if i == j:
			pass
		elif li[i][0] == li[j][1]:
			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 = []
guest = []
c = 0
for i in range(n):
	(x, y) = input().split()
	home.append(x)
	guest.append(y)
for i in guest:
	c += home.count(i)
print(c)


f = int(input())
a = []
b = []
for i in range(f):
	x = input()
	x = x.split()
	a.append(int(x[0]))
	b.append(int(x[1]))
co = 0
for i in a:
	for l in b:
		if i == l:
			co += 1
print(co)


from sys import *
input = stdin.readline
n = int(input())
a = []
b = []
for _ in range(n):
	(x, y) = map(int, input().split())
	a.append(x)
	b.append(y)
c = 0
for i in range(n):
	c += b[:i].count(a[i]) + b[i + 1:].count(a[i])
print(c)


kotobar = int(input())
shagotik = []
soforKari = []
for i in range(kotobar):
	(x, y) = map(int, input().split())
	shagotik.append(x)
	soforKari.append(y)
talika = []
for i in range(kotobar):
	talika.append(soforKari.count(shagotik[i]))
print(sum(talika))


count = int(input())
ans = 0
record = {}
for i in range(count):
	uniform = input().split(' ')
	record[i] = [uniform[0], uniform[1]]
for each in record.keys():
	for i in record.values():
		if record[each] == i:
			pass
		if record[each][0] == i[1]:
			ans += 1
		else:
			pass
print(ans)


n = int(input())
s = []
a = 0
for i in range(n):
	group = [int(x) for x in input().split()]
	s.append(group)
for i in range(n):
	for j in range(n):
		if s[i][0] == s[j][1]:
			a += 1
	for k in range(n):
		if s[i][1] == s[k][0]:
			a += 1
print(int(a / 2))


length = int(input(''))
arr = []
ans = 0
for i in range(length):
	arr.append([int(x) for x in input('').split()])
for i in range(length):
	currElement = arr[i][0]
	for j in range(length):
		if currElement == arr[j][1] and i != j:
			ans += 1
print(ans)


n = int(input())
dom_list = []
vyezd_list = []
for i in range(n):
	(dom, vyezd) = map(int, input().split())
	dom_list.append(dom)
	vyezd_list.append(vyezd)
counter = 0
for j in dom_list:
	for k in vyezd_list:
		if j == k:
			counter += 1
print(counter)


m = int(input())
a = list()
b = list()
for i in range(m):
	(x, y) = list(map(int, input().split()))
	a.append(x)
	b.append(y)
c = 0
i = 0
for i in range(m):
	for j in range(m):
		if a[i] == b[j] and i != j:
			c = c + 1
print(c)


n = int(input())
allTeams = []
for i in range(n):
	team = [int(s) for s in input().split()]
	allTeams.append(team)
count = 0
for i in range(n):
	for j in range(n):
		if allTeams[i][0] == allTeams[j][1]:
			count += 1
print(count)


n = int(input())
teams = []
answer = 0
for i in range(n):
	kit = list(map(int, input().split(' ')))
	teams.append(kit)
for i in range(n):
	host = i
	for x in range(n):
		if x == i:
			pass
		elif teams[i][0] == teams[x][1]:
			answer += 1
		else:
			pass
print(answer)


n = int(input())
res = 0
home = []
guest = []
while n > 0:
	(a, b) = input().split(' ')
	home.append(int(a))
	guest.append(int(b))
	n -= 1
for i in home:
	for j in guest:
		if i == j:
			res += 1
print(res)


n = int(input())
arr = []
ans = 0
for _ in range(n):
	(x, y) = map(int, input().split())
	arr.append([x, y])
for i in range(n):
	for j in range(i + 1, n):
		if arr[i][0] == arr[j][1]:
			ans += 1
		if arr[i][1] == arr[j][0]:
			ans += 1
print(ans)


n = int(input())
arr = []
c = 0
for _ in range(n):
	brr = list(map(int, input().split()))
	for i in range(_):
		c += (brr[0] == arr[i][1]) + (brr[1] == arr[i][0])
	arr.append(brr)
print(c)


n = int(input())
h = [0 for _ in range(n)]
a = [0 for _ in range(n)]
for i in range(n):
	(x, y) = list(map(int, input().split()))
	h[i] = x
	a[i] = y
s = 0
for i in range(n):
	for j in range(n):
		if i == j:
			continue
		if h[i] == a[j]:
			s += 1
print(s)


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


line = input()
line = int(line)
arr = [[0 for i in range(3)] for j in range(101)]
for i in range(line):
	(m, n) = input().split()
	m = int(m)
	n = int(n)
	arr[i][0] = m
	arr[i][1] = n
s = 0
for i in range(0, line):
	for j in range(0, line):
		if arr[i][0] == arr[j][1]:
			s += 1
print(s)


teams = int(input())
home = []
away = []
count = 0
for x in range(teams):
	colors = input().split(' ')
	home.append(int(colors[0]))
	away.append(int(colors[1]))
for a in home:
	for b in away:
		if a == b:
			count += 1
print(count)


n = int(input())
l1 = []
l2 = []
s1 = set([])
s2 = set([])
for i in range(n):
	(hi, ai) = [int(k) for k in input().split()]
	l1.append(hi)
	l2.append(ai)
	s1.add(hi)
out = 0
for c in s1:
	if c in l1 and c in l2:
		out += l1.count(c) * l2.count(c)
print(out)


n = int(input())
hc = []
hgc = {}
gc = []
ts = 0
s = 0
for i in range(n):
	(h, g) = [int(i) for i in input().split()]
	if (h, ts) in hgc:
		ts += 1
	hgc[h, ts] = g
	hc.append((h, ts))
for hu in hc:
	for (k, v) in hgc.items():
		if k == hc:
			continue
		gc.append(v)
	for gu in gc:
		if hu[0] == gu:
			s += 1
	gc.clear()
print(s)


def count(home, away_count):
	count = 0
	for h in home:
		if h in away_count:
			count += away_count.get(h)
	return count
n = int(input())
home = []
away_count = {}
for i in range(n):
	(h, a) = input().split(' ')
	home.append(h)
	if a in away_count:
		away_count[a] += 1
	else:
		away_count[a] = 1
print(count(home, away_count))


lst1 = []
lst2 = []
for i in range(int(input())):
	(a, b) = [int(i) for i in input().split()]
	lst1 = lst1 + [a]
	lst2 = lst2 + [b]
nd = 0
for i in lst2:
	for j in lst1:
		if i == j:
			nd += 1
print(nd)


n = int(input())
(H, A) = ([], [])
for i in range(n):
	(h, a) = [int(c) for c in input().split()]
	H.append(h)
	A.append(a)
ans = 0
for i in range(n):
	for j in range(n):
		if i != j:
			if H[i] == A[j]:
				ans += 1
print(ans)


teams = int(input())
uniform = list()
guest = 0
for i in range(teams):
	x = list(map(int, input().split()))
	uniform.append(x)
for j in range(teams):
	for k in range(teams):
		if j == k:
			continue
		elif uniform[j][0] == uniform[k][1]:
			guest = guest + 1
			continue
		else:
			continue
print(guest)


from itertools import permutations
x = int(input())
it = list(range(x))
y = list(permutations(it, 2))
a = list()
counter = 0
for i in range(x):
	a.append(tuple(map(int, input().split())))
for i in range(len(y)):
	if a[y[i][0]][0] == a[y[i][1]][1]:
		counter += 1
print(counter)


match = []
for _ in range(int(input())):
	hg = input().split()
	match.append(hg)
uniform = 0
for j in range(len(match)):
	for i in range(len(match)):
		if match[j][0] == match[i][1]:
			uniform = uniform + 1
print(uniform)


def games(values):
	count = 0
	for i in range(len(values)):
		final = values[0:i] + values[i + 1:]
		for j in range(len(final)):
			if values[i][1] == final[j][0]:
				count = count + 1
	return count
values = []
n = int(input())
for i in range(n):
	value = list(map(int, input().split()))
	values.append(value)
print(games(values))


n = int(input())
colorh = []
colorg = []
for i in range(n):
	L = input().split()
	colorh.append(L[0])
	colorg.append(L[1])
count = 0
for i in colorh:
	count += colorg.count(i)
print(count)


n = int(input())
d = dict()
for each_n in range(n):
	d[each_n + 1] = [int(i) for i in input().split()]
c = 0
for i in range(n):
	host_team_color = d[i + 1][0]
	for j in range(n):
		guest_team_color = d[j + 1][1]
		if i != j and host_team_color == guest_team_color:
			c += 1
print(c)


n = int(input())
s = [list(map(int, input().split())) for i in range(n)]
ans = 0
for ih in range(n):
	for ig in range(n):
		if ih == ig:
			continue
		if s[ih][0] == s[ig][1]:
			ans += 1
print(ans)


tn = int(input())
ans = 0
ls1 = []
ls2 = []
for i in range(tn):
	(a, b) = input().split(' ')
	ls1.append(a)
	ls2.append(b)
for k in range(tn):
	c = ls2.count(ls1[k])
	ans += c
print(ans)


n = int(input())
(a, b) = zip(*(input().split() for i in range(n)))
print(sum((a.count(i) for i in b)))


n = int(input())
b = []
sum = 0
for i in range(n):
	arr = [int(x) for x in input().split()]
	b.append(arr)
for i in range(n):
	for j in range(0, n):
		if b[i][0] == b[j][1] and b[i][0] != b[i][1]:
			sum += 1
print(sum)


games = int(input())
List = []
for game in range(games):
	(h, g) = map(int, input().split(' '))
	List.append(h)
	List.append(g)
count = 0
for i in range(len(List)):
	if i % 2 == 0:
		for k in range(len(List)):
			if k % 2 == 1 and k != i + 1:
				if List[k] == List[i]:
					count += 1
print(count)


def solve(a_list):
	sum = 0
	for i in range(len(a_list)):
		for k in range(len(a_list)):
			if i == k:
				pass
			elif a_list[i][0] == a_list[k][1]:
				sum += 1
	return sum

def main():
	n = int(input())
	a_list = []
	for i in range(n):
		(a, b) = map(int, input().split(' '))
		a_list.append((a, b))
	print(solve(a_list))
main()


x = int(input())
l = []
t = []
for i in range(x):
	(a, b) = map(int, input().split())
	l.append(a)
	t.append(b)
s = 0
for i in l:
	s += t.count(i)
print(s)


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


host = []
guest = []
count = 0
n = int(input())
for i in range(n):
	(h, g) = (int(x) for x in input().split())
	for gi in guest:
		if gi == h:
			count += 1
	for hi in host:
		if hi == g:
			count += 1
	host.append(h)
	guest.append(g)
print(count)


n = int(input())
m = [[0 for i in range(2)] for j in range(n)]
for k in range(n):
	(m[k][0], m[k][1]) = [int(a) for a in input().split()]
c = 0
for x in range(n):
	for y in range(n):
		if m[x][0] == m[y][1]:
			c += 1
print(c)


lst = []
for i in range(int(input())):
	lst.append(input().split())
cnt = 0
comb = 0
for ea in range(len(lst) - 1):
	for ea2 in range(ea + 1, len(lst)):
		comb += 2
		if lst[ea][0] == lst[ea2][1]:
			cnt += 1
		if lst[ea][1] == lst[ea2][0]:
			cnt += 1
print(cnt)


n = int(input())
l1 = list()
l2 = list()
for i in range(n):
	(a, b) = input().split()
	l1.append(a)
	l2.append(b)
cnt = 0
for i in l1:
	for j in l2:
		if i == j:
			cnt += 1
print(cnt)


import sys, math
n = int(input())
a = []
for i in range(n):
	t = list(map(int, input().split()))
	a.append(t)
res = 0
for i in range(n):
	for j in range(n):
		if i == j:
			continue
		k1 = a[i]
		k2 = a[j]
		if k1[0] == k2[1]:
			res += 1
print(res)


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


n = int(input())
a = []
x = 0
b = []
for i in range(n):
	(d, v) = map(int, input().split())
	a.append(d)
	b.append(v)
for i in range(n):
	for j in range(n):
		if a[i] == b[j]:
			x += 1
print(x)


a = int(input())
count = 0
b = []
c = []
for i in range(a):
	(d, e) = map(int, input().split())
	b.append(d)
	c.append(e)
for i in range(len(b)):
	count += c.count(b[i])
print(count)


n = int(input())
H = []
A = []
for i in range(0, n):
	s = input().split(' ')
	(h, a) = [int(s[i]) for i in range(0, 2)]
	H += [h]
	A += [a]
c = 0
for i in range(0, n):
	for j in range(0, n):
		if j != i:
			if H[i] == A[j]:
				c += 1
print(c)


def main():
	n = int(input())
	teams = []
	for _ in range(n):
		teams.append([int(a) for a in input().split(' ')])
	count = 0
	for i in range(n):
		for j in range(n):
			if i != j:
				if teams[i][0] == teams[j][1]:
					count += 1
	print(count)
main()


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


n = int(input())
h = []
g = []
for _ in range(n):
	(hc, gc) = map(int, input().split())
	h.append(hc)
	g.append(gc)
ans = 0
for i in range(n):
	for j in range(n):
		if i != j and h[i] == g[j]:
			ans += 1
print(ans)


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


total = input()
total = int(total)
host = []
guest = []
for num in range(total):
	(a, b) = map(int, input().split())
	host.append(a)
	guest.append(b)
ans = 0
for color in host:
	for guest_color in guest:
		if color == guest_color:
			ans += 1
print(ans)


n = int(input())
li = []
for i in range(n):
	t = tuple(map(int, input().split()))
	li.append(t)
h = 0
g = 1
count = 0
for i in range(n):
	for j in range(n):
		if i != j:
			if li[i][h] == li[j][g]:
				count += 1
print(count)


n = int(input())
uniforms = []
for i in range(n):
	(h, a) = [int(x) for x in input().split()]
	uniforms.append((h, a))
guest = 0
for i in range(n - 1):
	for j in range(i + 1, n):
		if uniforms[i][0] == uniforms[j][1]:
			guest += 1
		if uniforms[i][1] == uniforms[j][0]:
			guest += 1
print(guest)


count = 0
n = int(input())
a = [0] * n
b = [0] * n
for i in range(n):
	inp = input().split()
	a[i] = inp[0]
	b[i] = inp[1]
for i in range(n):
	for j in range(n):
		if a[i] == b[j]:
			count += 1
print(count)


A = list()
B = list()
c = 0
for _ in range(int(input())):
	(a, b) = input().split()
	A.append(a)
	B.append(b)
for i in A:
	c += B.count(i)
print(c)


n = int(input())
g = []
h = []
for i in range(n):
	k = []
	k.append(input().split())
	h.append(int(k[0][0]))
	g.append(int(k[0][1]))
count = 0
for i in range(n):
	count += g.count(h[i])
print(count)


n = int(input())
a = [[0 for i in range(2)] for i in range(30)]
sum = 0
for i in range(n):
	(a[i][0], a[i][1]) = [int(x) for x in input().split()]
for i in range(n):
	for j in range(n):
		if a[i][1] == a[j][0]:
			sum += 1
print(sum)


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


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


h = dict()
hs = set()
a = []
n = int(input())
for i in range(n):
	(x, y) = map(int, input().split())
	if x in hs:
		h[x] += 1
	else:
		h[x] = 1
		hs.add(x)
	a.append(y)
ans = 0
for i in a:
	ans += h.get(i, 0)
print(ans)


n = int(input())
(homeUni, guestUni) = ([None] * n, [None] * n)
gamesBothGuest = 0
for i in range(0, n):
	aux = input().split()
	(homeUni[i], guestUni[i]) = (int(aux[0]), int(aux[1]))
for i in range(0, n):
	gamesBothGuest = gamesBothGuest + guestUni.count(homeUni[i])
print(gamesBothGuest)


team = input()
host = []
guest = []
for i in range(0, int(team)):
	(h, g) = input().split()
	host.append(int(h))
	guest.append(int(g))

def Games(team, host, guest):
	cnt = 0
	for i in host:
		for j in guest:
			if i == j:
				cnt += 1
	return cnt
print(Games(team, host, guest))


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


def main():
	n = int(input())
	home = []
	guest = []
	output = 0
	for i in range(n):
		(h, g) = list(map(int, input().split()))
		home.append(h)
		guest.append(g)
	for j in home:
		output += sum([1 for i in guest if i == j])
	print(output)
main()


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


n = int(input())
(l, r, ans) = ([], [], 0)
for i in range(n):
	(x, y) = map(int, input().split())
	l.append(x)
	r.append(y)
for i in range(n):
	p = l[i]
	ans += r.count(p)
	if l[i] == r[i]:
		ans -= 1
print(ans)


n = int(input())
arr = []
for i in range(n):
	brr = list(map(int, input().strip().split()))[:2]
	arr.append(brr)
	brr = []
count = 0
for j in range(n):
	m = arr[j][0]
	k = 0
	while k < n:
		if k != j:
			if arr[k][1] == m:
				count = count + 1
				k = k + 1
			else:
				k = k + 1
		else:
			k = k + 1
print(count)


n = int(input())
h = []
a = []
b = 0
for i in range(n):
	(hx, ax) = map(int, input().split())
	h.append(hx)
	a.append(ax)
for i in range(len(h)):
	b += a.count(h[i])
print(b)


n = int(input())
a = []
b = []
f = 0
for i in range(n):
	(k, m) = map(int, input().split())
	a.append(k)
	b.append(m)
for x in a:
	t = a.index(x)
	h = b[t]
	p = b[t:]
	p.remove(h)
	f += b.count(x)
	p.insert(0, h)
print(f)


t = int(input())
a = []
b = []
for i in range(t):
	(h, g) = input().split()
	a.append(int(h))
	b.append(int(g))
	c = 0
for j in range(len(a)):
	for k in range(len(b)):
		if j != k:
			if a[j] == b[k]:
				c += 1
print(c)


a = int(input())
home_clothes = []
front_clothes = []
for i in range(a):
	b = input()
	b = b.split()
	home_clothes.append(b[0])
	front_clothes.append(b[1])
summa = 0
for i in home_clothes:
	for u in front_clothes:
		if i == u:
			summa += 1
print(summa)


import sys
import os.path
if os.path.exists('in.txt'):
	sys.stdin = open('in.txt', 'r')
	sys.stdout = open('out.txt', 'w')
n = int(input())
li = []
li2 = []
ans = 0
for i in range(n):
	(b, c) = map(int, input().split())
	li.append(b)
	li2.append(c)
for i in range(n):
	for j in range(n):
		if li[i] == li2[j]:
			ans += 1
print(ans)


from collections import deque, Counter
import array
from itertools import combinations, permutations
from math import sqrt
import unittest

def read_int():
	return int(input().strip())

def read_int_array():
	return [int(i) for i in input().strip().split(' ')]
n = read_int()
teams = []
for i in range(n):
	teams += [read_int_array()]
count = 0
for (i, t1) in enumerate(teams):
	for (j, t2) in enumerate(teams):
		if i == j:
			continue
		if t1[0] == t2[1]:
			count += 1
print(count)


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


x = int(input())
s = 1
l = []
suml = 0
while s <= x:
	(a, b) = map(int, input().split())
	l.append(a)
	l.append(b)
	s += 1
e = 0
lent = x * 2 - 1
d = lent
while d > 2:
	z = 3
	while lent > 2:
		if lent - z >= 0:
			if l[lent - z] == l[d]:
				suml += 1
				z += 2
			else:
				z += 2
		else:
			lent -= 2
			break
	d -= 2
b = len(l) - 2
lentt = len(l) - 2
while b > 1:
	n = 1
	while lentt > 1:
		if lentt - n >= 0:
			if l[lentt - n] == l[b]:
				suml += 1
				n += 2
			else:
				n += 2
		else:
			lentt -= 2
			break
	b -= 2
print(suml)


n = int(input())
lis = []
for i in range(n):
	lis.append(input().split())
count = 0
for i in range(n):
	for j in range(n):
		if j != i and lis[j][1] == lis[i][0]:
			count += 1
print(count)


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)


n = int(input())
a = []
b = []
for _ in range(n):
	(a1, b1) = map(int, input().split())
	a.append(a1)
	b.append(b1)
c = 0
for i in range(n):
	for j in range(n):
		if a[i] == b[j]:
			c += 1
print(c)


x = input()
y = []
for i in range(int(x)):
	test = input()
	test = list(map(int, test.strip().split()))
	y.append(test)
count = 0
for j in range(len(y)):
	temp = y[j]
	for i in range(len(y)):
		if i == j:
			continue
		temp2 = y[i]
		if temp[1] == temp2[0]:
			count += 1
print(str(count))


n = int(input())
a = [input().split() for _ in range(n)]
ans = 0
for i in range(n):
	for j in range(n):
		if i != j and a[i][0] == a[j][1]:
			ans += 1
print(ans)


n = int(input())
home = []
guests = []
for _ in range(n):
	(a, b) = [int(i) for i in input().split(' ')]
	home.append(a)
	guests.append(b)
changes = 0
for home_color in home:
	for guest_color in guests:
		if home_color == guest_color:
			changes += 1
print(changes)


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


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


t = int(input())
list_a = []
list_b = []
while t:
	(a, b) = map(int, input().split())
	list_a.append(a)
	list_b.append(b)
	t -= 1
count = 0
for i in list_b:
	if i in list_a:
		count += list_a.count(i)
print(count)


number_team = int(input())
home_uniforms = []
away_uniforms = []
conflict = 0
for i in range(number_team):
	new_team = input().split()
	home_uniforms.append(new_team[0])
	away_uniforms.append(new_team[1])
for i in home_uniforms:
	for j in away_uniforms:
		if i == j:
			conflict += 1
print(conflict)


n = int(input())
hosts = []
guests = []
for i in range(n):
	(a, b) = map(int, input().split())
	hosts.append(a)
	guests.append(b)
c = 0
for i in hosts:
	c += guests.count(i)
print(c)


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


import math
import cmath
from decimal import *
from fractions import *
n = int(input())
(a, b) = ([], [])
res = 0
for _ in range(n):
	x = list(map(int, input().split()))
	a.append(x[0])
	b.append(x[1])
for x in a:
	res += b.count(x)
print(res)


lst = [list(map(int, input().split())) for _ in range(int(input()))]
count = 0
for i in lst:
	for j in lst:
		if i[1] == j[0]:
			count += 1
print(count)


n = int(input())
lis = []
for i in range(n):
	lis.append(input().split())
slon = 0
for i in range(n):
	for j in range(n):
		if i != j:
			if lis[i][0] == lis[j][1]:
				slon += 1
print(slon)


h = {}
g = {}
n = int(input())
output = 0
for _ in range(n):
	(hc, gc) = [int(i) for i in input().split(' ')]
	if g.get(hc) is not None:
		output += g.get(hc)
	if h.get(gc) is not None:
		output += h.get(gc)
	h.setdefault(hc, 0)
	g.setdefault(gc, 0)
	h[hc] += 1
	g[gc] += 1
print(output)


(home, away) = ([], [])
n = int(input())
p = 0
for _ in range(n):
	(x, y) = map(int, input().split())
	home.append(x)
	away.append(y)
for i in range(n):
	for j in range(n):
		if away[j] == home[i]:
			p += 1
print(p)


n = int(input())
A = []
ans = 0
pos = 1
for i in range(n):
	a = input()
	b = a.split()
	A.append(b)
for i in A[0:-1]:
	h = i[0]
	g = i[1]
	for x in A[pos:]:
		if h == x[1]:
			ans += 1
		if g == x[0]:
			ans += 1
	pos += 1
print(ans)


n = int(input())
m = [[int(i) for i in input().split()] for j in range(n)]
(h, g, c) = ([], [], 0)
for i in range(n):
	h.append(m[i][0])
	g.append(m[i][1])
for i in range(n):
	c += g.count(h[i])
print(c)


n = int(input())
l = []
ans = 0
for f in range(n):
	t = list(map(int, input().split()))
	l.append(t)
for f1 in range(n - 1):
	for f2 in range(f1 + 1, n):
		if l[f1][0] == l[f2][1]:
			ans += 1
		if l[f1][1] == l[f2][0]:
			ans += 1
print(ans)


def Games():
	n = int(input().strip())
	home_uni = []
	away_uni = []
	host_away_uni = 0
	for i in range(n):
		(h, a) = map(int, input().strip().split())
		home_uni.append(h)
		away_uni.append(a)
	for uni in home_uni:
		host_away_uni += away_uni.count(uni)
	return host_away_uni
a = Games()
print(a)


def game(H, A, n):
	count = 0
	for i in range(n):
		for j in range(n):
			if i != j and H[i] == A[j]:
				count += 1
	return count
n = int(input())
(H, A) = ([], [])
for i in range(n):
	(h, a) = map(int, input().split())
	H.append(h)
	A.append(a)
print(game(H, A, n))


import sys
if False:
	input = open('uniforms.txt', 'r')
else:
	input = sys.stdin
n = int(input.readline())
home = []
guest = []
for i in range(n):
	team = input.readline().split()
	home.append(team[0])
	guest.append(team[1])
counter = 0
for h in home:
	for g in guest:
		if h == g:
			counter = counter + 1
print(counter)


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


N = int(input())
S = []
for i in range(N):
	s = list((int(x) for x in input().split()))
	S.extend(s)
A = []
B = []
for i in range(0, N * 2 - 1, 2):
	A.append(S[i])
	B.append(S[i + 1])
c = 0
for i in range(N):
	for j in range(N):
		if B[j] == A[i]:
			c += 1
print(c)


n = int(input())
k = 0
a = []
b = []
for i in range(n):
	(c1, c2) = map(int, input().split())
	a.append(c1)
	b.append(c2)
for i in a:
	k += b.count(i)
print(k)


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


n = int(input())
H = []
G = []
for i in range(n):
	(h, g) = map(int, input().split())
	H.append(h)
	G.append(g)
ans = 0
for i in range(n):
	for j in range(n):
		if i != j and H[i] == G[j]:
			ans += 1
print(ans)


n = int(input())
home = list()
away = list()
for i in range(n):
	words = input().split()
	home.append(int(words[0]))
	away.append(int(words[1]))
count = 0
for i in range(n):
	for j in range(n):
		if i == j:
			continue
		if away[i] == home[j]:
			count += 1
print(count)


n = int(input())
list = []
cnt = 0
for i in range(n):
	(a, b) = input().split(' ')
	a = int(a)
	b = int(b)
	list.append(a)
	list.append(b)
for j in range(2 * n):
	cnt1 = 0
	for k in range(j + 1, 2 * n, 2):
		if list[j] == list[k]:
			cnt1 += 1
	cnt += cnt1
print(cnt)


from sys import stdin
from collections import Counter
n = int(stdin.readline())
(c0, c1) = (Counter(), Counter())
tot = 0
for _ in range(n):
	(a, b) = stdin.readline().split()
	tot += c1[a] + c0[b]
	c0[a] += 1
	c1[b] += 1
print(tot)


n = int(input())
l1 = []
l2 = []
for i in range(n):
	(a, b) = [int(x) for x in input().split()]
	l1.append(a)
	l2.append(b)
x = 0
for i in range(n):
	x = x + l2.count(l1[i])
print(x)


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


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)


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


n = int(input())
lis = []
for i in range(n):
	lis.append(list(map(int, input().split(' '))))
ans = 0
for (i, elem) in enumerate(lis):
	for (j, elem1) in enumerate(lis):
		if i != j and elem[0] == elem1[1]:
			ans += 1
print(ans)


n = int(input())
arr = []
for i in range(n):
	s = input().split()
	arr.append(s)
count = 0
for i in range(n):
	s1 = arr[i]
	for j in range(i + 1, n):
		s2 = arr[j]
		if s1[0] == s2[1]:
			count = count + 1
		if s1[1] == s2[0]:
			count = count + 1
print(count)


n = int(input())
L = []
for i in range(n):
	[h, a] = [int(j) for j in input().split(' ')]
	L.append([h, a])
count = 0
for x in range(len(L)):
	for y in range(len(L)):
		if x != y:
			if L[x][0] == L[y][1]:
				count += 1
print(count)


n = int(input())
from collections import defaultdict
d = defaultdict(list)
d['h'] = []
d['a'] = []
for i in range(0, n):
	(h, a) = map(int, input().split())
	d['h'].append(h)
	d['a'].append(a)
h = d['h']
a = d['a']
cnt = 0
for i in h:
	for j in a:
		if i == j:
			cnt += 1
print(cnt)


def change_uniform(colors):
	result = 0
	for v in colors.values():
		result += v[0] * v[1]
	return result
n = int(input())
colors = dict()
for i in range(n):
	(color_h, color_g) = input().split()
	for (i, color) in enumerate((color_h, color_g)):
		colors.setdefault(color, [0, 0])[i] += 1
result = change_uniform(colors)
print(result)


n = int(input())
team = []
s = 0
for i in range(n):
	team.append([int(x) for x in input().split()])
for i in range(n):
	for j in range(n):
		if team[i][0] == team[j][1]:
			s += 1
print(s)


n = int(input())
count = 0
home = []
away = []
for i in range(n):
	ha = input()
	(h, a) = (int(i) for i in ha.split())
	home.append(h)
	away.append(a)
for j in range(n):
	for k in range(n):
		if home[j] == away[k]:
			count += 1
		elif home[j] == away[k]:
			count += 1
print(count)


def count(elem, l):
	c = 0
	for i in l:
		if i == elem:
			c += 1
	return c
n = int(input())
l1 = []
l2 = []
for i in range(n):
	(x, y) = map(int, input().split())
	l1.append(x)
	l2.append(y)
ans = 0
for i in l2:
	ans += count(i, l1)
print(ans)


h = []
a = []
res = 0
for i in range(int(input())):
	(x, y) = map(int, input().split())
	h.append(x)
	a.append(y)
for k in h:
	for e in a:
		if k == e:
			res += 1
print(res)


import sys
from random import choice, randint
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20
eps = 1.0 / 10 ** 10
mod = 10 ** 9 + 7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]

def MI():
	return map(int, sys.stdin.readline().strip().split())

def LI():
	return list(map(int, sys.stdin.readline().strip().split()))

def LLI():
	return [list(map(int, l.split())) for l in sys.stdin.readlines().strip()]

def LI_():
	return [int(x) - 1 for x in sys.stdin.readline().strip().split()]

def LF():
	return [float(x) for x in sys.stdin.readline().strip().split()]

def LS():
	return sys.stdin.readline().strip().split()

def I():
	return int(sys.stdin.readline().strip())

def F():
	return float(sys.stdin.readline().strip())

def S():
	return sys.stdin.readline().strip()

def pf(s):
	return print(s, flush=True)

def pe(s):
	return print(str(s), file=sys.stderr)

def JA(a, sep):
	return sep.join(map(str, a))

def JAA(a, s, t):
	return s.join((t.join(map(str, b)) for b in a))
inp = sys.stdin.readline
out = sys.stdout.write

def main():
	n = I()
	l = []
	for i in range(n):
		(h, a) = MI()
		l.append([h, a])
	c = 0
	for i in range(n):
		for j in range(n):
			(x, y) = (l[i], l[j])
			if i != j and x[0] == y[1]:
				c += 1
	pf(c)
main()


t = int(input())
h = []
g = []
for i in range(t):
	(i, j) = map(int, input().split())
	h.append(i)
	g.append(j)
count = 0
for i in h:
	count += g.count(i)
print(count)


n = int(input())
t = []
for i in range(n):
	t = t + [list(map(int, input().split()))]
x = 0
for i in range(n - 1):
	for j in range(i + 1, n):
		if t[i][0] == t[j][1]:
			x = x + 1
		if t[i][1] == t[j][0]:
			x = x + 1
print(x)


number_teams = int(input())
number_games = number_teams * (number_teams - 1)
equipos_camisetas = []
contador = 0
for repetir in range(number_teams):
	colores_camisetas = input().split()
	equipos_camisetas.append(colores_camisetas)
for numeros_locales in range(number_teams):
	locales = equipos_camisetas[numeros_locales][0]
	for numeros_rivales in range(number_teams):
		rivales = equipos_camisetas[numeros_rivales][1]
		if locales == rivales:
			contador += 1
print(contador)


m = int(input())
teams = []
for _ in range(m):
	c = [int(v) for v in input().split(' ')]
	teams.append(c)
count = 0
for i in range(m):
	for z in range(m):
		if i == z:
			continue
		if teams[i][0] == teams[z][1]:
			count = count + 1
print(count)


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


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


n = int(input())
vertical1 = []
vertical2 = []
swaps = 0
for i in range(0, n):
	line = input().split(' ')
	vertical1.append(line[0])
	vertical2.append(line[1])
for uniform in vertical1:
	swaps += vertical2.count(uniform)
print(swaps)


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


t = int(input())
z = 0
lst = []
lst1 = []
for t in range(t):
	(p, q) = map(int, input().split())
	lst.append(p)
	lst1.append(q)
t += 1
for i in range(t):
	for j in range(t):
		if i != j:
			if lst[i] == lst1[j]:
				z += 1
print(z)


number_of_teams = input()
array_of_teams = []
counter = 0
for x in range(int(number_of_teams)):
	array_of_teams.append(input().split(' '))
for x in range(len(array_of_teams)):
	for n in range(len(array_of_teams)):
		if x == n:
			continue
		if array_of_teams[x][0] == array_of_teams[n][1]:
			counter += 1
print(counter)


def color_match(colors):
	color_match = 0
	guest_colors = {}
	for color in colors:
		if color[1] not in guest_colors:
			guest_colors[color[1]] = 1
		else:
			guest_colors[color[1]] += 1
	for color in colors:
		if color[0] in guest_colors:
			color_match += guest_colors[color[0]]
	return color_match
colors = []
for _ in range(int(input())):
	colors.append(list(map(int, input().split())))
print(color_match(colors))


try:
	n = int(input())
	l = []
	k = n
	while k:
		(x, y) = map(int, input().split())
		l.append([x, y])
		k -= 1
	i = 0
	c = 0
	while i < n:
		j = i
		while j < n:
			if l[i][0] == l[j][1]:
				c += 1
			if l[i][1] == l[j][0]:
				c += 1
			j += 1
		i += 1
	print(c)
except:
	pass


n = int(input())
teams = []
for _ in range(n):
	teams.append(list(map(int, input().split())))
count = 0
for (i, host) in enumerate(teams):
	for (j, guest) in enumerate(teams):
		if i != j:
			if guest[1] == host[0]:
				count += 1
print(count)


def check_similarColors(team1, team2, count):
	team1 = [int(x) for x in team1.split()]
	team2 = [int(x) for x in team2.split()]
	if team1[0] == team2[1]:
		count += 1
	if team1[1] == team2[0]:
		count += 1
	return count
n = int(input())
teams = []
for i in range(n):
	teams.append(input())
output = 0
for i in range(n - 1):
	for j in range(i + 1, n):
		output = check_similarColors(teams[i], teams[j], output)
print(output)


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)


co = 0
lis1 = []
lis2 = []
n = int(input())
for i in range(n):
	(a, b) = map(int, input().split())
	lis1.append(a)
	lis2.append(b)
for i in range(len(lis1)):
	a = lis1[i]
	for i in range(len(lis2)):
		if a == lis2[i]:
			co += 1
print(co)


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


def main():
	lgames = []
	nteams = int(input())
	for i in range(nteams):
		lgames.append(tuple(map(int, input().split())))

	def games(lgames, nteams):
		counter = 0
		for team in range(nteams):
			current_team = lgames[team]
			for agnist_team in lgames:
				if current_team[0] == agnist_team[1]:
					counter += 1
		return counter
	print(games(lgames, nteams))
main()


n = int(input().strip())
colors = []
for _ in range(n):
	colors.append(list(map(int, input().strip().split())))
changes = 0
for hi in range(n):
	for gi in range(n):
		if hi == gi:
			continue
		hostColor = colors[hi][0]
		guestColor = colors[gi][1]
		if hostColor == guestColor:
			changes += 1
print(changes)


n = int(input())
l = []
r = []
for i in range(n):
	a = list(map(int, input().split(' ')))
	l.append(a[0])
	r.append(a[1])
count = 0
for i in l:
	if i in r:
		count += r.count(i)
print(count)


n = int(input())
arr = []
dic = {}
for i in range(n):
	arr.append([int(i) for i in input().split()])
	if arr[-1][1] not in dic:
		dic[arr[-1][1]] = 1
	else:
		dic[arr[-1][1]] += 1
ans = 0
for i in range(n):
	if arr[i][0] in dic:
		col = arr[i][0]
		p = dic[col]
		ans += p
print(ans)


s = int(input())
(h, g, c) = ([], [], 0)
while s:
	(x, y) = map(int, input().split())
	(h.append(x), g.append(y))
	s -= 1
for i in h:
	if i in g:
		c += g.count(i)
print(c)


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


data = []
for _ in range(int(input())):
	data.append(list(map(int, input().split())))
result = 0
for i in data:
	for j in data:
		if i != j and i[0] == j[1]:
			result += 1
print(result)


import sys
n = int(sys.stdin.readline())
h = []
a = []
count = 0
for i in range(n):
	team = sys.stdin.readline().split(' ')
	h.append(team[0])
	a.append(team[1].strip('\n'))
for i in range(n):
	for j in range(n):
		if h[i] == a[j]:
			count += 1
print(count)


__author__ = 'runekri3'
n = int(input())
home_uniforms = []
guest_uniforms = []
for _ in range(n):
	(home, guest) = list(map(int, input().split()))
	home_uniforms.append(home)
	guest_uniforms.append(guest)
searched_games = 0
for home_uniform in home_uniforms:
	searched_games += guest_uniforms.count(home_uniform)
print(searched_games)


n = int(input())
answer = 0
forms = []
for i in range(n):
	(h, a) = map(int, input().split())
	forms.append([h, a])
for home in range(n - 1):
	for guest in range(home + 1, n):
		if forms[home][0] == forms[guest][1]:
			answer += 1
		if forms[home][1] == forms[guest][0]:
			answer += 1
print(answer)


a = [input().split() for i in range(int(input()))]
print(sum((a[i][0] == a[j][1] for i in range(len(a)) for j in range(len(a)))))


n = int(input())
l1 = []
l2 = []
ans = 0
for i in range(n):
	a = input().partition(' ')
	l1.append(a[0])
	l2.append(a[2])
for i in range(n):
	for j in range(n):
		if l1[i] == l2[j]:
			ans += 1
print(ans)


n = int(input())
L = []
c = 0
for i in range(n):
	L += [[int(x) for x in input().split()]]
for a in range(n):
	for b in range(a + 1, n):
		if L[a][0] == L[b][1]:
			c += 1
		if L[a][1] == L[b][0]:
			c += 1
print(c)


n = int(input())
home = []
away = []
res = 0
for i in range(n):
	take = list(map(int, input().split()))
	home.extend([take[0]])
	away.extend([take[1]])
for i in range(n):
	res += away.count(home[i])
print(res)


n = int(input())
i = 0
home = []
guest = []
while i < n:
	(a, b) = map(int, input().split(' '))
	home.append(a)
	guest.append(b)
	i += 1
ans = 0
for i in home:
	ans += guest.count(i)
print(ans)


def games(a):
	count = 0
	for i in range(len(a)):
		for j in range(len(a)):
			if a[i][0] == a[j][1]:
				count = count + 1
	print(count)
n = int(input(''))
a = []
for i in range(n):
	b = list(map(int, input('').split()))
	a.append(b)
games(a)


N = int(input())
Loc = []
Vis = []
for k in range(N):
	L = input()
	L = L.split()
	Local = int(L[0])
	Visitante = int(L[1])
	Loc.append(Local)
	Vis.append(Visitante)
Contador = 0
for k in range(len(Loc)):
	for i in range(len(Vis)):
		if Loc[i] == Vis[k]:
			Contador += 1
print(Contador)


n = int(input())
home = []
guest = []
for i in range(n):
	(m, n) = [int(x) for x in input().split()]
	home.append(m)
	guest.append(n)
num = 0
for i in range(len(home)):
	s = home[i]
	num += guest.count(s)
print(int(num))


x = int(input())
lst = []
lst2 = []
out = 0
for i in range(x):
	(y, z) = map(int, input().split())
	lst.append(y)
	lst2.append(z)
for j in range(x):
	for k in range(x):
		if lst[j] == lst2[k]:
			out += 1
print(out)


x = int(input())
a = []
b = []
counter = 0
for i in range(x):
	y = input()
	y = y.split()
	y = list(map(int, y))
	a.append(y[0])
	b.append(y[1])
for i in range(x):
	for f in range(x):
		if a[i] == b[f]:
			counter += 1
print(counter)


n = int(input())
x = [0] * n
y = [0] * n
for i in range(0, n):
	(x[i], y[i]) = [int(x) for x in input().split()]
count = 0
for i in range(0, n):
	for j in range(0, n):
		if i == j:
			continue
		elif x[i] == y[j]:
			count += 1
print(count)


n = int(input())
a = []
b = []
j = 0
for i in range(0, n):
	arr = [int(u) for u in input().split()]
	a.append(arr[0])
	b.append(arr[1])
for numbers in a:
	for numb in b:
		if numbers == numb:
			j = j + 1
		else:
			pass
print(j)


n = int(input())
colors = []
for _ in range(n):
	colors.append([int(c) for c in input().split(' ')])
ja = 0
for elem in colors:
	temp = colors[:]
	temp.remove(elem)
	for t in temp:
		if elem[0] == t[1]:
			ja += 1
print(ja)


(n, a, b) = (int(input()), [], [])
for _ in [0] * n:
	(x, y) = map(int, input().split())
	a += [x]
	b += [y]
print(sum((b.count(x) for x in a)))


n = int(input())
answer = 0
team = list(map(int, input().split()))
for j in range(n - 1):
	tmp = list(map(int, input().split()))
	i = 1
	while i <= len(team):
		if tmp[0] == team[i]:
			answer = answer + 1
		i = i + 2
	i = 0
	while i < len(team):
		if tmp[1] == team[i]:
			answer = answer + 1
		i = i + 2
	team.extend(tmp)
print(str(answer))


x = int(input())
c = []
for i in range(x):
	(z, y) = input().split()
	c.append((z, y))
output = 0
for j in range(x):
	for k in range(x):
		if k != j:
			if c[j][0] == c[k][1]:
				output += 1
print(output)


import sys
n = int(input())
colors = [[0, 0]] * n
for i in range(n):
	colors[i] = list(map(int, sys.stdin.readline().split()))
ret = 0
for i in range(n):
	for j in range(n):
		if j != i and colors[i][1] == colors[j][0]:
			ret += 1
print(ret)


x = int(input())
(s, t) = zip(*(input().split() for _ in ' ' * x))
print(sum((s.count(i) for i in t)))


def hostGuest(tuples: list) -> int:
	numberOfChanges = 0
	for i in range(len(tuples)):
		for j in range(len(tuples)):
			if i != j:
				if tuples[i][0] == tuples[j][1]:
					numberOfChanges += 1
	return numberOfChanges

def main():
	n = int(input().strip())
	tuples = []
	for _ in range(n):
		(host, guest) = map(int, input().strip().split())
		tuples.append((host, guest))
	print(hostGuest(tuples))
main()


k = 0
Home = []
Out = []
n = int(input())
for i in range(n):
	(home, out) = list(map(int, input().split()))
	Home.append(home)
	Out.append(out)
for home in Home:
	for out in Out:
		if home == out:
			k += 1
print(k)


a = int(input())
li = []
li2 = []
s = 0
for i in range(a):
	(b, c) = map(int, input().split())
	li.append(b)
	li2.append(c)
for i in range(a):
	for j in range(a):
		if li[i] == li2[j]:
			s += 1
print(s)


n = int(input())
no_of_games = n * (n - 1)
teams = []
output = 0
homes = []
aways = []
for i in range(n):
	teams.append(input())
for i in teams:
	(home, away) = i.split()
	homes.append(home)
	aways.append(away)
for i in homes:
	for j in aways:
		if i == j:
			output += 1
print(output)


n = int(input())
res = [list(map(int, input().split())) for i in range(n)]
home = [res[i][0] for i in range(n)]
out = [res[i][1] for i in range(n)]
k = 0
for c in home:
	k += out.count(c)
print(k)


n = int(input())
aw = []
h = []
for i in range(n):
	(a, b) = map(int, input().split())
	h.append(a)
	aw.append(b)
cnt = 0
for i in range(n):
	for j in range(n):
		if i != j and h[i] == aw[j]:
			cnt += 1
print(cnt)


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


n = int(input())
line = []
for i in range(n):
	line += input().split()
line = [int(i) for i in line]
count = 0
for i in range(n):
	host = line[2 * i]
	for j in range(n):
		guest = line[2 * j + 1]
		if host == guest:
			count += 1
print(count)


ar = []
n = int(input())
b = 0
for i in range(0, n):
	ha = input().split()
	h = ha[0]
	a = ha[1]
	ar.append((h, a))
for i in range(0, n):
	for j in range(0, n):
		if j == i:
			continue
		elif ar[i][0] == ar[j][1]:
			b = b + 1
print(b)


n = int(input())
h = [0] * n
a = [0] * n
for x in range(n):
	(h[x], a[x]) = [int(x) for x in input().split()]
nb_games = 0
for x in range(n):
	for y in range(n):
		if x == y:
			continue
		if h[x] == a[y]:
			nb_games += 1
print(nb_games)


teams = []
n = int(input())
for i in range(n):
	teams.append(list(map(int, input().strip().split())))
n_guest = 0
for i in range(n):
	matches = list(teams)
	matches.pop(i)
	for match in matches:
		if teams[i][0] == match[1]:
			n_guest += 1
print(n_guest)


n = int(input())
(arra, arrb) = ([], [])
sum = 0
for x in range(0, n):
	arrin = [int(x) for x in input().split()]
	arra.append(arrin[0])
	arrb.append(arrin[1])
for x in range(0, n):
	sum += arrb.count(arra[x])
print(sum)


n = int(input())
h = [0] * n
g = [0] * n
for i in range(n):
	(h[i], g[i]) = list(map(int, input().split()))
count = 0
for i in range(n):
	home = h[i]
	for j in range(n):
		if home == g[j]:
			count += 1
print(count)


n = int(input())
teams = [0] * n
for i in range(n):
	string = input().split()
	for j in range(2):
		string[j] = int(string[j])
	teams[i] = string
res = 0
for i in range(n):
	for j in range(n):
		if teams[i][0] == teams[j][1]:
			res += 1
print(res)


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


Team_Uniforms = []
for team in range(int(input())):
	Team_Uniforms.append(list(map(int, input().split())))
c = 0
for i in Team_Uniforms:
	for j in Team_Uniforms:
		if i[0] == j[1]:
			c += 1
print(c)


n = int(input())
home_form_list = []
visit_form_list = []
for i in range(n):
	(home_form, visit_form) = [x for x in input().split()]
	home_form_list.append(home_form)
	visit_form_list.append(visit_form)
counter = 0
for h in home_form_list:
	for v in visit_form_list:
		if h == v:
			counter += 1
print(counter)


import math

def nCr(n, r):
	f = math.factorial
	return f(n) / f(r) / f(n - r)
n = int(input())
home = []
guest = []
c = 0
for i in range(n):
	s = input().split(' ')
	home.append(int(s[0]))
	guest.append(int(s[1]))
for i in home:
	if i in guest:
		c += guest.count(i)
print(c)


n = int(input())
home_unis = []
guest_unis = []
result = 0
for i in range(n):
	(home, guest) = list(map(int, input().split(' ')))
	home_unis.append(home)
	guest_unis.append(guest)
for i in range(n):
	host_color = home_unis[i]
	tests = guest_unis[0:i]
	if i != n:
		tests.extend(guest_unis[i + 1:])
	result += tests.count(host_color)
print(result)


teams = int(input())
localColors = []
guestColors = []
changes = 0
for i in range(teams):
	teami = [int(i) for i in str(input()).split()]
	localColors.append(teami[0])
	guestColors.append(teami[1])
for local in localColors:
	for guest in guestColors:
		if local == guest:
			changes += 1
print(changes)


n = int(input())
b = []
while n > 0:
	(h, a) = input().split()
	b.append([h, a])
	n -= 1
c = list(zip(*b))
d = [x for x in c[0] for y in c[1] if x == y]
print(len(d))


num_teams = int(input())
home_colors = [0] * num_teams
guest_colors = [0] * num_teams
for i in range(num_teams):
	(home_colors[i], guest_colors[i]) = map(int, input().split())
count = 0
for home in range(num_teams):
	for guest in range(num_teams):
		if home != guest:
			if home_colors[home] == guest_colors[guest]:
				count += 1
print(count)


from collections import defaultdict as dd

def lcm(a, b):
	return a * b // gcd(a, b)

def inin():
	return int(input())

def inar():
	return list(map(int, input().split()))

def ar(element, size):
	return [element for i in range(size)]

def digitsum(num):
	su = 0
	while num:
		su += num % 10
		num //= 10
	return su

def yes():
	print('YES')

def no():
	print('NO')

def countDivisibles(A, B, M):
	if A % M == 0:
		return B // M - A // M + 1
	return B // M - A // M

def countSetBits(n):
	count = 0
	while n:
		count += n & 1
		n >>= 1
	return count
Testcase = 1
for _ in range(Testcase):
	n = inin()
	arr = []
	for i in range(n):
		(a, b) = inar()
		arr.append((a, b))
	ss = 0
	for i in range(n):
		for j in range(n):
			if i == j:
				continue
			if arr[i][0] == arr[j][1]:
				ss += 1
	print(ss)


n = int(input(''))
arr1 = []
arr2 = []
same = 0
for i in range(n):
	(home, away) = list(map(int, input('').strip().split()))
	arr1.append(home)
	arr2.append(away)
for j in range(n):
	for k in range(n):
		if arr1[j] == arr2[k]:
			same += 1
		else:
			continue
print(same)


from collections import Counter
n = int(input())
h = []
g = []
for i in range(n):
	(x, y) = input().split()
	h.append(int(x))
	g.append(int(y))
h = Counter(h)
g = Counter(g)
s = 0
for key in h.keys():
	s += h.get(key, 0) * g.get(key, 0)
print(s)


z = 0
H = []
G = []
n = int(input())
x = 0
while x < n:
	x = x + 1
	(h, g) = input().split()
	H.append(h)
	G.append(g)
for i in H:
	for s in G:
		if i == s:
			z = z + 1
print(z)


n = int(input())
buf = 0
d = list()
v = list()
for i in range(n):
	b = list(map(int, input().split()))
	d.append(b[0])
	v.append(b[1])
for i in v:
	buf += d.count(i)
print(buf)


n = int(input())
L = []
for i in range(n):
	(a, b) = map(int, input().split())
	L.append(a)
	L.append(b)
num = 0
for i in range(0, n * 2, 2):
	for j in range(1, n * 2, 2):
		if L[i] == L[j]:
			num += 1
print(num)


teams = [input().split(' ') for i in range(int(input()))]
times = 0
for (i, team1) in enumerate(teams[:-1]):
	for team2 in teams[i + 1:]:
		if team1[0] == team2[1]:
			times += 1
		if team1[1] == team2[0]:
			times += 1
print(times)


n = int(input())
teams = []
for _ in range(n):
	teams.append(list(map(int, input().split())))
ans = 0
for (i, team) in enumerate(teams):
	for j in range(len(teams)):
		if not i == j:
			if team[0] == teams[j][1]:
				ans += 1
print(ans)


n = int(input())
home = []
away = []
for i in range(n):
	a = input().split()
	home.append(int(a[0]))
	away.append(int(a[1]))
c = 0
for a in away:
	c += home.count(a)
print(c)


import sys
input = sys.stdin.readline

def inp():
	return int(input())

def inlt():
	return list(map(int, input().split()))

def insr():
	s = input()
	return list(s[:len(s) - 1])

def invr():
	return map(int, input().split())
n = inp()
h = []
a = []
for i in range(n):
	(x, y) = invr()
	h.append(x)
	a.append(y)
count = 0
for i in range(n):
	for j in range(n):
		if h[i] == a[j]:
			count = count + 1
print(count)


n = int(input(''))
l = []
p = []
for i in range(n):
	(x, y) = [int(x) for x in input('').split()]
	l.append(x)
	p.append(y)
count = 0
for i in l:
	for j in p:
		if i == j:
			count = count + 1
print(count)


import sys

def play_game(t1, t2):
	if t1[0] == t2[1]:
		return 1
	else:
		return 0

def main():
	sys_in = sys.stdin
	sys_out = sys.stdout
	n = int(sys_in.readline())
	teams = []
	for i in range(n):
		temp = tuple(map(int, sys_in.readline().split()))
		teams.append(temp)
	ans = 0
	for i in range(len(teams)):
		for j in range(len(teams)):
			if i != j:
				ans += play_game(teams[i], teams[j])
	sys_out.write(f'{ans}')
main()


n = int(input())
list1 = []
list2 = []
c = 0
for i in range(n):
	(a, b) = [int(x) for x in input().split()]
	list1.append(a)
	list2.append(b)
for i in range(len(list1)):
	for j in range(len(list2)):
		if list1[i] == list2[j]:
			c += 1
print(c)


def matches(lst1, lst2, n):
	count = 0
	for i in range(n):
		for j in range(n):
			if lst1[i] == lst2[j]:
				count += 1
	return count
m = int(input())
(b, c) = (list(), list())
for i in range(m):
	(h, a) = [int(i) for i in input().split()]
	b.append(h)
	c.append(a)
print(matches(b, c, m))


count = int(input())
home_color = []
guest_color = []
color_matches = 0
for i in range(count):
	color = input().split(' ')
	home_color.append(color[0])
	guest_color.append(color[1])
for a in list(home_color):
	color_matches += guest_color.count(a)
print(color_matches)


amountOfTeams = int(input())
teams = []
requiredOutfitChanges = 0
while amountOfTeams > 0:
	teams.append(input().split(' '))
	amountOfTeams = amountOfTeams - 1
for (i, firstTeam) in enumerate(teams, start=1):
	for secondTeam in teams[i:]:
		if firstTeam[0] == secondTeam[1]:
			requiredOutfitChanges = requiredOutfitChanges + 1
		if firstTeam[1] == secondTeam[0]:
			requiredOutfitChanges = requiredOutfitChanges + 1
print(requiredOutfitChanges)


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


n = int(input())
s1 = []
t = 0
for j in range(n):
	s = input().split()
	for i in range(1):
		i = j * 2
		s1.append(int(s[0], 10))
		s1.append(int(s[1], 10))
for i in range(1, n * 2, 2):
	for j in range(0, n * 2 - 1, 2):
		if s1[i] == s1[j]:
			t += 1
print(t)


n = int(input())
h = []
a = []
for _n in range(n):
	(p, q) = map(int, input().split())
	h.append(p)
	a.append(q)
count = 0
for i in range(n):
	for j in range(n):
		if i != j and h[i] == a[j]:
			count += 1
print(count)


import sys
it = iter(sys.stdin.read().splitlines())
n = int(next(it))
teamColors = []
counter = 0
for i in range(n):
	teamColors.append([int(x) for x in next(it).split(' ')])
for i in range(n):
	for j in range(n):
		if i != j:
			if teamColors[i][0] == teamColors[j][1]:
				counter += 1
print(counter)


n = int(input())
hostarr = [0] * n
d = dict()
s = 0
for i in range(n):
	[host, guest] = list(map(int, input().split()))
	if guest in d:
		d[guest] += 1
	else:
		d[guest] = 1
	hostarr[i] = host
for i in hostarr:
	if i in d:
		s += d[i]
print(s, end='')


import sys
input = sys.stdin.readline
data = []
for _ in range(int(input().rstrip())):
	data.append(list(map(int, input().rstrip().split())))
cnt = 0
for t1 in data:
	for t2 in data:
		if t1 != t2 and t1[1] == t2[0]:
			cnt += 1
print(cnt)


n = int(input())
a = []
for i in range(n):
	a.append(input().split(' '))
count = 0
for i in range(len(a)):
	for j in range(i + 1, len(a)):
		if a[i][0] == a[j][1]:
			count += 1
		if a[i][1] == a[j][0]:
			count += 1
print(count)


n = int(input())
home = []
guest = []
for i in range(n):
	(h, g) = [int(x) for x in input().split()]
	home.append(h)
	guest.append(g)
games = 0
for h in home:
	for g in guest:
		if h == g:
			games += 1
print(games)


def getGuestTimes(n, arr):
	x = []
	y = []
	sum = 0
	for i in range(0, len(arr)):
		if i % 2 == 0:
			x.append(arr[i])
		else:
			y.append(arr[i])
	for i in x:
		for j in y:
			if i == j:
				sum += 1
	return sum
num = int(input())
arr = []
for i in range(0, int(num)):
	n = input().split(' ')
	arr += n
print(getGuestTimes(num, arr))


def Main():
	n = int(input())
	arr = []
	tmp = list(map(int, input().split()))
	arr.append(tmp)
	ans = 0
	for _ in range(n - 1):
		tmp = list(map(int, input().split()))
		for i in range(len(arr)):
			if arr[i][0] == tmp[1]:
				ans += 1
			if arr[i][1] == tmp[0]:
				ans += 1
		arr.append(tmp)
	print(ans)
Main()


a = int(input())
ho = []
aw = []
clash = 0
for i in range(a):
	(p, q) = map(int, input().split())
	ho.append(p)
	aw.append(q)
for j in ho:
	for k in aw:
		if j == k:
			clash += 1
		else:
			continue
	else:
		continue
print(clash)


import sys
teams = int(input())
lst = []
count = 0
for i in range(teams):
	row = []
	row = list(map(int, input().split()))
	lst.append(row)
for i in range(teams - 1):
	for j in range(i + 1, teams):
		if lst[i][0] == lst[j][1]:
			count += 1
		if lst[i][1] == lst[j][0]:
			count += 1
print(count)


n = int(input())
hostTeam = []
guestTeam = []
count = 0
for i in range(n):
	a = list(map(int, input().strip().split()))[:2]
	hostTeam.append(a[0])
	guestTeam.append(a[1])
for dress in guestTeam:
	for uniform in hostTeam:
		if dress == uniform:
			count += 1
print(count)


n = int(input())
v = 0
x = []
for i in range(n):
	(z, y) = map(int, input().split())
	x.append(z)
	x.append(y)
i = 0
while len(x) != 0:
	for s in range(i + 1, len(x), 2):
		if x[i] == x[s]:
			v += 1
	del x[i]
print(v)


def countfun(num, nums):
	c = 0
	for n in nums:
		if n == num:
			c += 1
	return c
n = int(input())
(home, away) = ([], [])
for i in range(n):
	(h, a) = tuple(map(int, input().split()))
	home.append(h)
	away.append(a)
total = 0
for hom in home:
	total += countfun(hom, away)
print(total)


n = int(input())
(l, lw) = ([], [])
for i in range(n):
	(a, b) = [int(x) for x in input().split()]
	l.append(a)
	lw.append(b)
s = 0
for i in range(n):
	t = l[i]
	for k in range(n):
		if t == lw[k]:
			s += 1
print(s)


n = int(input())
m = n
h = []
a = []
while n > 0:
	n = n - 1
	l = [int(i) for i in input().split()]
	h.append(l[0])
	a.append(l[1])
c = 0
for i in range(len(h)):
	for j in range(len(a)):
		if h[i] == a[j]:
			c = c + 1
print(c)


n = int(input())
teams = []
for i in range(n):
	teams.append((int(x) for x in input().split()))
(host, guest) = zip(*teams)
res = 0
for i in host:
	res += guest.count(i)
print(res)


num_teams = int(input())
team_uniforms = [tuple(map(int, input().split())) for idx in range(num_teams)]
count = 0
for host in range(num_teams):
	for guest in list(range(0, host)) + list(range(host, num_teams)):
		if team_uniforms[host][0] == team_uniforms[guest][1]:
			count += 1
print(count)


n = int(input())
one = []
two = []
for _ in range(n):
	(a, b) = list(map(int, input().split()))
	one.append(a)
	two.append(b)
di = {}
for i in two:
	if i not in di:
		di[i] = 1
	else:
		di[i] += 1
num = 0
for i in one:
	if i in di:
		num += di[i]
print(num)


n = int(input())
dicHome = {}
dicVisit = {}
count = 0
for i in range(0, n):
	(h, v) = input().split()
	dicHome[str(h)] = dicHome[str(h)] + 1 if str(h) in dicHome else 1
	dicVisit[str(v)] = dicVisit[str(v)] + 1 if str(v) in dicVisit else 1
for (key, value) in dicHome.items():
	if key in dicVisit:
		count += dicVisit[key] * value
print(count)


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


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


n = int(input())
colors = []
for _ in range(n):
	colors.append([int(h) for h in input().split()])
matches = 0
for i in range(n - 1):
	for j in range(i, n):
		if colors[i][0] == colors[j][1]:
			matches += 1
		if colors[i][1] == colors[j][0]:
			matches += 1
print(matches)


n = int(input())
m = []
arr = []
for i in range(n):
	m.append(list(map(int, input().split())))
for j in range(2):
	for i in range(n):
		arr.append(m[i][j])
brr = arr[:n]
crr = arr[n:]
c = 0
for i in brr:
	if i in crr:
		c1 = crr.count(i)
		c += c1
print(c)


a = int(input())
list1 = []
list2 = []
for i in range(0, a):
	(y, x) = input().split()
	list1.append(int(y))
	list2.append(int(x))
result = 0
for j in range(0, a):
	for l in range(0, a):
		if list1[j] == list2[l]:
			result = result + 1
print(result)


def sort(arr):
	count = 0
	for i in range(len(arr) - 1):
		for j in range(i + 1, len(arr)):
			if arr[i][0] == arr[j][1]:
				if arr[i][1] == arr[j][0]:
					count += 2
				else:
					count += 1
			elif arr[i][1] == arr[j][0]:
				count += 1
	print(count)
arr = []
n = int(input())
for i in range(n):
	arr.append(list(map(int, input().split())))
sort(arr)


from sys import stdin, stdout, exit as sys_ret
(f_input, f_print, f_flush) = (stdin.readline, stdout.write, stdout.flush)
amount = int(f_input())
teams = [[int(_) for _ in f_input().split()] for i in range(amount)]
count = 0
for i in range(amount):
	for j in range(amount):
		if i != j and teams[i][0] == teams[j][1]:
			count += 1
f_print(str(count))


n = int(input())
home = []
guest = []
count = 0
for i in range(n):
	color = [x for x in input().split()]
	home.append(color[0])
	guest.append(color[1])
for element in home:
	count += guest.count(element)
print(count)


n = int(input())
homes = []
guests = []
ans = 0
for i in range(n):
	(a, b) = input().split()
	homes.append(a)
	guests.append(b)
for h in homes:
	for g in guests:
		if g == h:
			ans += 1
print(ans)


n = int(input())
arr = []
arr1 = []
cnt = 0
for i in range(n):
	(h, a) = map(int, input().split())
	if len(arr) == 0:
		arr.append(h)
		arr1.append(a)
	else:
		if h in arr1:
			cnt += arr1.count(h)
		if a in arr:
			cnt += arr.count(a)
		arr.append(h)
		arr1.append(a)
print(cnt)


n = int(input())
doubles = 0
home = []
away = []
for i in range(n):
	(h, a) = list(map(int, input().split()))
	home.append(h)
	away.append(a)
for h in home:
	doubles += away.count(h)
print(doubles)


n = int(input())
h = []
a = []
games = 0
for i in range(n):
	arr = input().split()
	h.append(int(arr[0]))
	a.append(int(arr[1]))
for hu in h:
	for au in a:
		if hu == au:
			games += 1
		else:
			pass
print(games)


def main():
	n = int(input())
	tab1 = [0] * n
	tab2 = [0] * n
	for i in range(n):
		(tab1[i], tab2[i]) = map(int, input().split())
	somme = 0
	for elem in tab1:
		for elem2 in tab2:
			if elem == elem2:
				somme += 1
	print(somme)
main()


n = int(input())
c = 0
l = [(a, b) for (a, b) in (map(int, input().split()) for _ in ' ' * n)]
for i in range(n):
	for j in range(i + 1, n):
		c += (l[i][0] == l[j][1]) + (l[i][1] == l[j][0])
print(c)


w = int(input())
a = []
c = 0
for i in range(0, w):
	p = input().split()
	a.append(p)
for i in range(0, w):
	r = a[i]
	for j in range(0, w):
		s = a[j]
		if int(r[0]) == int(s[1]):
			c = c + 1
print(c)


n = int(input())
m = []
for i in range(n):
	(h, a) = map(int, input().split(' '))
	m.append((h, a))
c = 0
for i in range(n):
	for j in range(n):
		if i == j:
			continue
		if m[i][0] == m[j][1]:
			c += 1
print(c)


n = int(input())
l = []
count = 0
for i in range(n):
	l.append(tuple(map(int, input().split())))
for i in range(n):
	for j in range(n):
		if i == j:
			continue
		if l[i][0] == l[j][1]:
			count += 1
print(count)


lis = []
lis2 = []
n = int(input())
i = 0
while i < n:
	(x, y) = input().split()
	lis.append(x)
	lis2.append(y)
	i += 1
lis2.sort()
mth = 0
i = 0
while i < n:
	j = 0
	while j < n:
		if lis[i] == lis2[j]:
			mth += 1
		if lis[i] < lis2[j]:
			break
		j += 1
	i += 1
print(mth)


n = int(input())
l1 = []
l2 = []
f = 0
for i in range(n):
	(t1, t2) = list(input().split())
	l1.append(t1)
	l2.append(t2)
for item in l1:
	for i in l2:
		if item == i:
			f += 1
print(f)


count = int(input())
form = []
cnt = int(0)
for i in range(count):
	form.append(list(map(int, input().split())))
for i in form:
	for j in form:
		if i[0] == j[1]:
			cnt += 1
print(cnt)


tc = int(input())
c = 0
l = []
for x in range(tc):
	(home, away) = map(int, input().split())
	l.append([home, away])
for i in range(len(l)):
	s = l[i][0]
	for j in range(tc):
		if s == l[j][1]:
			c += 1
print(c)


a = int(input())
(l, m, f) = ([], [], 0)
for i in range(a):
	(b, c) = map(int, input().split())
	(l.append(b), m.append(c))
for item in m:
	f += l.count(item)
print(f)


t = int(input())
u = []
total = 0
for n in range(t):
	u.append(input().split())
for c in range(t):
	for m in range(t):
		if c != m and u[c][0] == u[m][1]:
			total += 1
print(total)


l = []
n = int(input())
count = 0
for i in range(0, n):
	(a, b) = map(int, input().split())
	l.append([a, b])
for item in l:
	for i in range(0, n):
		if l.index(item) != i:
			if item[0] == l[i][-1]:
				count += 1
print(count)


import itertools
n = int(input())
host = []
guess = []
for _ in range(n):
	colors = list(map(int, input().split()))
	host.append(colors[0])
	guess.append(colors[1])
prod = itertools.product(host, guess)
print(len([tup for tup in prod if tup[0] == tup[1]]))


h = []
g = []
ans = 0
for i in range(int(input())):
	t = [int(x) for x in input().split()]
	h.append(t[0])
	g.append(t[1])
for i in h:
	ans += g.count(i)
print(ans)


import sys
import math
import bisect
from sys import stdin, stdout
from math import gcd, floor, sqrt, log
from collections import defaultdict as dd
from bisect import bisect_left as bl, bisect_right as br
sys.setrecursionlimit(100000000)
ii = lambda : int(input())
si = lambda : input()
jn = lambda x, l: x.join(map(str, l))
sl = lambda : list(map(str, input().strip()))
mi = lambda : map(int, input().split())
mif = lambda : map(float, input().split())
lii = lambda : list(map(int, input().split()))
ceil = lambda x: int(x) if x == int(x) else int(x) + 1
ceildiv = lambda x, d: x // d if x % d == 0 else x // d + 1
flush = lambda : stdout.flush()
stdstr = lambda : stdin.readline()
stdint = lambda : int(stdin.readline())
stdpr = lambda x: stdout.write(str(x))
mod = 1000000007
n = ii()
h = []
g = []
count = 0
for i in range(n):
	(a, b) = mi()
	h.append(a)
	g.append(b)
for i in range(n):
	for j in range(n):
		if h[i] == g[j]:
			count += 1
print(count)


n = int(input())
h = {}
g = {}
for i in range(n):
	(a, b) = map(int, input().split())
	h[a] = h.get(a, 0) + 1
	g[b] = g.get(b, 0) + 1
ans = 0
for (k, v) in h.items():
	ans += h[k] * g.get(k, 0)
print(ans)


import math
import collections
import bisect
import heapq
import time
import random
import itertools
import sys
N = int(input())
(H, A) = ([], [])
for i in range(N):
	(h, a) = map(int, input().split())
	H.append(h)
	A.append(a)
ans = 0
for h in H:
	ans += A.count(h)
print(ans)


n = int(input().strip())
uniforms = []
for _ in range(n):
	uniforms.append(list(map(int, input().strip().split())))
count = 0
host_uniform_idx = 0
gues_uniform_idx = 1
for i in range(n):
	for j in range(n):
		if uniforms[i][host_uniform_idx] == uniforms[j][gues_uniform_idx]:
			count += 1
print(count)


n = int(input())
A = []
for i in range(n):
	x = list(map(int, input().strip().split(' ')))
	A.append(x)
guest = 0
for j in range(0, n):
	for k in range(0, n):
		if A[j][0] == A[k][1]:
			guest += 1
print(guest)


t = int(input())
l1 = []
l2 = []
count = 0
while t:
	l = [int(x) for x in input().split()]
	l1.append(l[0])
	l2.append(l[1])
	t = t - 1
for i in range(len(l1)):
	for j in range(len(l2)):
		if l1[i] == l2[j]:
			count = count + 1
print(count)


t = int(input())
c = 0
x = []
for i in range(t):
	x.append([int(x) for x in input().split()])
for i in range(t):
	for j in range(i + 1, t):
		if x[i][0] == x[j][1]:
			c += 1
		if x[i][1] == x[j][0]:
			c += 1
print(c)


teams = int(input())
colors = dict()
count = 0
for i in range(teams):
	colors[i] = [int(s) for s in input().split()]
for i in range(teams):
	for j in range(teams):
		if i == j:
			continue
		if colors[i][0] == colors[j][1]:
			count += 1
print(count)


n = int(input())
l = [0 for x in range(n)]
for i in range(n):
	l[i] = [int(x) for x in input().split()]
flag = 0
for i in range(n):
	for j in range(n):
		if l[i][0] == l[j][1]:
			flag = flag + 1
print(flag)


t = int(input())
m1 = list()
m2 = list()
for i in range(t):
	(a, b) = list(map(int, input().split()))
	m1.append(a)
	m2.append(b)
num = 0
for i in m1:
	num = num + m2.count(i)
print(num)


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


def answer():
	n = int(input())
	i = 0
	(e, f) = ([], [])
	while i < n:
		b = input().split()
		(c, d) = (b[0], b[1])
		e.append(c)
		f.append(d)
		i += 1
	i = 0
	ans = 0
	while i < len(e):
		j = 0
		while j < len(f):
			if f[j] == e[i]:
				ans += 1
			j += 1
		i += 1
	return ans
print(answer())


n = int(input())
a = []
h = []
b = []
for i in range(n):
	(x, y) = map(int, input().split())
	a.append(x)
	h.append(y)
for m in a:
	if m in h:
		c = h.count(m)
		b.append(c)
print(sum(b))


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


n = input()
val = []
for x in range(int(n)):
	c = input()
	val.append(c)
ans = 0
for x in val:
	for x2 in val:
		if x != x2:
			x1 = x.split(' ')
			x22 = x2.split(' ')
			if x1[0] == x22[1]:
				ans += 1
print(ans)


teams = input()
home = []
guest = []
for i in range(0, int(teams)):
	team_colors = input().split()
	home.append(team_colors[0])
	guest.append(team_colors[1])
exceptions = 0
for i in range(0, len(home)):
	for j in range(0, len(guest)):
		if home[i] == guest[j]:
			exceptions = exceptions + 1
print(exceptions)


n = int(input())
a = [0] * n
b = [0] * n
j = i = t = 0
while i < n:
	(a[i], b[i]) = map(int, input().split())
	i += 1
i = 0
while j < n:
	while i < n:
		if a[j] == b[i]:
			t += 1
		i += 1
	j += 1
	i = 0
print(t)


n = int(input())
teams = [list(map(int, input().split())) for _ in range(n)]
print(sum((teams[i][0] == teams[j][1] for i in range(n) for j in range(n))))


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


N = int(input())
A = []
B = []
Sum = 0
for I in range(N):
	Inpt = list(map(int, input().split()))
	A.append(Inpt[0])
	B.append(Inpt[1])
for I in range(N):
	for J in range(N):
		if A[I] == B[J]:
			Sum += 1
print(Sum)


n = int(input())
h_u = []
g_u = []
while n:
	li = [int(i) for i in input().split()]
	h_u.append(li[0])
	g_u.append(li[1])
	n -= 1
cou = 0
for i in range(len(g_u)):
	cou += g_u.count(h_u[i])
print(cou)


n = int(input())
h = list()
g = list()
c = 0
for i in range(n):
	hg = input().split(' ')
	h = h + [hg[0]]
	g = g + [hg[1]]
for i in range(n):
	for j in range(n):
		if h[i] == g[j]:
			c = c + 1
print(c)


def proA(arr):
	ans = 0
	for i in range(len(arr)):
		for j in range(i + 1, len(arr)):
			(p, q) = (arr[i], arr[j])
			if p[0] == q[1]:
				ans += 1
			if p[1] == q[0]:
				ans += 1
	return ans
t = int(input())
arr = []
for i in range(t):
	arr1 = list(map(int, input().split()))
	arr.append(arr1)
print(proA(arr))


n = int(input())
home = []
away = []
count = 0
for i in range(n):
	(m, n) = map(int, input().split())
	home.append(m)
	away.append(n)
for i in range(len(home)):
	for j in range(len(away)):
		if home[i] == away[j]:
			count += 1
print(count)


n = int(input())
res = []
count = 0
for _ in range(n):
	a = list(map(int, input().strip().split(' ')))
	res.append(a)
for i in range(len(res) - 1):
	for j in range(i + 1, len(res)):
		if res[i][1] == res[j][0] and res[i][0] != res[j][1]:
			count += 1
		elif res[i][0] == res[j][1] and res[i][1] != res[j][0]:
			count += 1
		elif res[i][1] == res[j][0] and res[i][0] == res[j][1]:
			count += 2
print(count)


n = int(input())
L = []
K = []
sum = 0
for i in range(n):
	(a, b) = map(int, input().split())
	L.append(a)
	K.append(b)
for i in L:
	sum += K.count(i)
print(sum)


n = int(input())
arr = []
for _ in range(n):
	arr.append(list(map(int, input().split())))
c = 0
for i in range(n - 1):
	for j in range(i + 1, n):
		if arr[i][0] == arr[j][1] and arr[i][1] == arr[j][0]:
			c += 2
		elif arr[i][0] != arr[j][1] and arr[i][1] == arr[j][0]:
			c += 1
		elif arr[i][0] == arr[j][1] and arr[i][1] != arr[j][0]:
			c += 1
print(c)


n = int(input())
arr = []
l = 0
for i in range(n):
	arr.append(input().strip().split())
for i in range(n):
	for g in range(n):
		if i == g:
			continue
		a = arr[i]
		b = arr[g]
		if a[0] == b[1]:
			l += 1
print(l)


def func(n):
	l = []
	for i in range(n):
		k = list(map(int, input().split()))
		l.append(k)
	counter = 0
	for i in range(len(l)):
		for j in range(len(l)):
			if l[i][0] == l[j][1]:
				counter += 1
	print(counter)
n = int(input())
func(n)


t = int(input())
l = []
c = 0
for i in range(t):
	(h, a) = map(int, input().split())
	l.append((h, a))
for i in l:
	for j in l:
		if j != i:
			if i[0] == j[1]:
				c += 1
print(c)


n = int(input())
t = []
for i in range(n):
	l = list(map(int, input().strip().split()))
	t += [l]
c = 0
for i in range(len(t)):
	for j in range(len(t)):
		if t[i][0] == t[j][1]:
			c += 1
print(c)


n = int(input())
home = dict()
away = dict()
ans = 0
for i in range(n):
	(h, a) = input().split()
	if h not in home:
		home[h] = home.get(h, 0) + 1
	else:
		home[h] = home.get(h) + 1
	if a not in away:
		away[a] = away.get(a, 0) + 1
	else:
		away[a] = away.get(a) + 1
	if h in away:
		ans += away[h]
	if a in home:
		ans += home[a]
print(ans)


n = int(input())
count = 0
host = []
guest = []
for i in range(n):
	(a, b) = [int(x) for x in input().split()]
	host.append(a)
	guest.append(b)
for i in range(n):
	number = host[i]
	for j in range(n):
		if number == guest[j]:
			count += 1
print(count)


import itertools

def read_ints():
	return list(map(int, input().split()))
team_colors_home = []
team_colors_away = []
for _ in range(int(input())):
	value = read_ints()
	team_colors_home.append(value[0])
	team_colors_away.append(value[1])
result = list(filter(lambda elem: elem[0] == elem[1], list(itertools.product(team_colors_away, team_colors_home))))
print(len(result))


while True:
	n = int(input())
	if n >= 2 and n <= 30:
		break
teams_colors = []
for i in range(n):
	teams_colors.append(input().split(' '))
count = 0
for i in teams_colors:
	for j in teams_colors:
		if i[0] == j[1]:
			count += 1
print(count)


n = input()
n = int(n)
first_teams = []
second_teams = []
for i in range(n):
	inputting = input().split()
	first_teams += inputting[0].split()
	second_teams += inputting[1].split()
counter = 0
for i in range(len(first_teams)):
	for j in range(len(second_teams)):
		if i == j:
			continue
		elif first_teams[i] == second_teams[j]:
			counter += 1
print(counter)


(v, m) = ([], [])
for _ in range(int(input())):
	(a, b) = map(int, input().split())
	v.append(a)
	m.append(b)
s = 0
for i in v:
	s += m.count(i)
print(s)


n = int(input())
hi = []
gi = []
for i in range(n):
	(m, k) = map(int, input().split())
	hi.append(m)
	gi.append(k)
count = 0
for i in hi:
	for j in gi:
		if i == j:
			count += 1
print(count)


n = int(input())
ho = []
gue = []
for i in range(n):
	(h, g) = map(int, input().split(' '))
	ho.append(h)
	gue.append(g)
s = 0
for i in ho:
	s = s + gue.count(i)
print(s)


n = int(input())
a = list()
for i in range(n):
	a.append(list(map(int, input().split(' '))))
x = 0
for i in range(n):
	g = i
	if i != 0:
		g = 0
	while g != n:
		if g == i:
			g += 1
			if g == n:
				print(x)
				exit()
		if a[i][0] == a[g][1]:
			x += 1
		g += 1
print(x)


n = int(input())
(m1, m2) = ([], [])
for i in range(n):
	m = [int(i) for i in input().split(' ')]
	m1.append(m[0])
	m2.append(m[1])
a = 0
for i in m1:
	for j in m2:
		if i == j:
			a += 1
print(a)


ans = 0
home = {}
guest = {}
for _ in range(int(input())):
	(h, g) = tuple(map(int, input().split()))
	home[h] = home.get(h, 0) + 1
	guest[g] = guest.get(g, 0) + 1
for (k, v) in home.items():
	ans += v * guest.get(k, 0)
print(ans)


from collections import defaultdict
home = defaultdict(int)
out = defaultdict(int)
count = 0
for _ in range(int(input())):
	(a, b) = map(int, input().split())
	home[a] += 1
	out[b] += 1
for a in home:
	if a in out:
		count += home[a] * out[a]
print(count)


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


n = int(input())
arr1 = []
arr2 = []
count = 0
for i in range(n):
	b = list(map(int, input().split()))
	arr1.append(b[0])
	arr2.append(b[1])
for i in range(len(arr1)):
	for j in range(len(arr2)):
		if i != j and arr1[i] == arr2[j]:
			count += 1
print(count)


n = int(input())
res = 0
d = {}
for i in range(n):
	d[i] = list(map(int, input().split()))
for i in range(n):
	home_color = d[i][0]
	away_colors = [d[t][1] for t in range(n) if t != i]
	res += away_colors.count(home_color)
print(res)


def seperateints(x):
	k = ''
	l = []
	for i in x:
		if i == ' ':
			l.append(int(k))
			k = ''
			continue
		k = k + i
	l.append(int(k))
	return l

def luckynum(x):
	for i in x:
		if i != '4' and i != '7':
			return False
	return True
n = int(input())
l = []
for i in range(n):
	l.append(seperateints(input()))
nn = 0
for i in range(n):
	for k in range(n):
		if k <= i:
			continue
		if l[i][1] == l[k][0]:
			nn += 1
		if l[i][0] == l[k][1]:
			nn += 1
print(nn)


n = int(input())
al = []
bl = []
m = 0
for i in range(n):
	(ai, bi) = map(int, input().split())
	al.append(ai)
	bl.append(bi)
for i in range(n):
	t = bl[i] * 1
	if t in al:
		p = al.count(t)
		m += p
print(m)


__author__ = 'myduomilia'

class Command:

	def __init__(self, a, b):
		self.a = a
		self.b = b
n = int(input())
(arr, ans) = ([], 0)
for i in range(n):
	(a, b) = list(map(int, input().split()))
	arr.append(Command(a, b))
for i in range(n):
	for j in range(n):
		if i != j:
			if arr[i].a == arr[j].b:
				ans += 1
print(ans)


team = int(input())
home = []
guest = []
for i in range(0, team):
	(h, g) = input().split()
	home = home + [int(h)]
	guest = guest + [int(g)]
hpig = 0
for i in range(0, team):
	for j in range(0, team):
		if i != j:
			if home[i] == guest[j]:
				hpig = hpig + 1
print(hpig)


n = int(input())
arr = []
c = 0
for _ in range(n):
	(h, a) = map(int, input().split())
	arr.append([h, a])
for i in range(n):
	for j in range(i + 1, n):
		if arr[i][0] == arr[j][1] and arr[i][1] == arr[j][0]:
			c += 2
		elif arr[i][0] == arr[j][1] or arr[i][1] == arr[j][0]:
			c += 1
print(c)


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())
s = []
m = []
cnt = 0
for i in range(n):
	a = list(map(int, input().split()))
	s.append(a[1])
	m.append(a[0])
for w in m:
	for e in s:
		if w == e:
			cnt += 1
print(cnt)


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)))


(lst, l) = ([], [])
(m, n) = (0, 0)
for i in range(int(input())):
	(a, b) = map(int, input().split())
	lst.append(a)
	l.append(b)
	for j in range(len(l)):
		if a == l[j]:
			m = m + 1
		if b == lst[j]:
			m = m + 1
print(m)


n = int(input())
jerseys = []
for _ in range(n):
	jerseys.append([int(i) for i in input().split()])
count = 0
for i in range(n):
	for j in range(n):
		if i != j:
			if jerseys[i][0] == jerseys[j][1]:
				count += 1
print(count)


t = int(input())
b = []
for i in range(t):
	(h, g) = map(int, input().split())
	b.append(h)
	b.append(g)
temp = 0
count = 0
for j in range(len(b)):
	temp = b[j]
	for k in range(j + 1, len(b)):
		if b[k] == temp:
			if abs(j - k) == 1 or (j - k - 2) % 3 == 0 or (j - k) % 2 == 1:
				if (j - k) % 2 != 0:
					count = count + 1
		else:
			pass
print(count)


x = []
y = []
m = 0
for i in range(int(input())):
	(a, b) = list(map(int, input().split()))
	x.append(a)
	y.append(b)
for i in x:
	for o in y:
		if i == o:
			m += 1
print(m)


from itertools import combinations
n = int(input())
l = [tuple(map(int, input().split(' '))) for _ in range(n)]
matches = combinations(range(n), 2)
c = 0
for x in matches:
	team1 = x[0]
	team2 = x[1]
	hostcolor = lambda team_colors: team_colors[0]
	awaycolor = lambda team_colors: team_colors[1]
	if hostcolor(l[team1]) == awaycolor(l[team2]):
		c += 1
	if hostcolor(l[team2]) == awaycolor(l[team1]):
		c += 1
print(c)


N = int(input())
V = [0] * N
L = [0] * N
CI = 0
for i in range(N):
	(A, B) = [int(x) for x in input().split()]
	V[i] = A
	L[i] = B
for i in range(N):
	E = V[i]
	Aux = L[i]
	for j in range(i + 1, N):
		if E == L[j]:
			CI += 1
		if Aux == V[j]:
			CI += 1
print(CI)


n = int(input())
teams = []
for i in range(n):
	teams.append(list(map(int, input().split())))
res = 0
for specific_team in range(n):
	for each_other_team in range(n):
		if specific_team != each_other_team and teams[specific_team][0] == teams[each_other_team][1]:
			res += 1
print(res)


arr = []
ans = 0
for _ in range(int(input())):
	arr.append(list(map(int, input().split())))
for i in range(len(arr)):
	for j in range(len(arr)):
		if j != i:
			if arr[i][0] == arr[j][1]:
				ans += 1
print(ans)


a = int(input())
b = [[i, i] for i in range(a)]
for i in range(a):
	c = input().split()
	b[i][0] = int(c[0])
	b[i][1] = int(c[1])
s = 0
for i in range(a):
	for j in range(a):
		if b[i][0] == b[j][1] and i != j:
			s += 1
print(s)


n = int(input())
team = []
count = 0
for i in range(n):
	(home, quest) = map(int, input().split())
	team.append([home, quest])
for i in range(n - 1):
	for j in range(i + 1, n):
		if team[i][0] == team[j][1]:
			count += 1
		if team[i][1] == team[j][0]:
			count += 1
print(count)


(list_home, list_guest, cnt) = ([], [], 0)
for _ in range(int(input().strip())):
	tmp_list = [int(x) for x in input().strip().split()]
	list_home.append(tmp_list[0])
	list_guest.append(tmp_list[1])
for x in list_home:
	for y in list_guest:
		if x == y:
			cnt += 1
print(cnt)


n = int(input())
teams = [[int(i) for i in input().split()] for j in range(n)]
counter = 0
for x in range(len(teams)):
	for y in range(len(teams)):
		if teams[x][0] == teams[y][1]:
			counter += 1
print(counter)


no = int(input())
h = []
g = []
ans = 0
for each in range(no):
	(home, guest) = list(input().split())
	h.append(home)
	g.append(guest)
for each in g:
	ans += h.count(each)
print(ans)


n = int(input())
h = []
g = []
t = 0
for i in range(n):
	(a, b) = map(str, input().split())
	h.append(a)
	g.append(b)
for i in range(n):
	c = h[i]
	for j in range(n):
		if i != j:
			if g[j] == h[i]:
				t += 1
print(t)


def games(l):
	count = 0
	for j in range(0, len(l)):
		for k in range(0, len(l)):
			if l[j][0] == l[k][1]:
				count += 1
	return count
n = int(input())
l = []
for i in range(0, n):
	a = list(map(int, input().split()))
	l.append(a)
	a = []
print(games(l))


n = int(input())
h = []
g = []
for i in range(n):
	st = input().split()
	h.append(int(st[0]))
	g.append(int(st[1]))
count = 0
for i in range(n):
	for j in range(n):
		if h[i] == g[j] and i != j:
			count += 1
print(count)


from sys import stdin, stdout
from math import gcd, sqrt, floor, ceil

def list_inp(x):
	return list(map(x, input().split()))

def map_inp(x):
	return map(x, input().split())

def lcm(a, b):
	return a * b / gcd(a, b)
t = int(input())
home = []
away = []
for _ in range(t):
	(h, a) = map_inp(int)
	home.append(h)
	away.append(a)
cnt = 0
for i in range(t):
	cnt += away.count(home[i])
print(cnt)


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


(n, a, b, ans) = (int(input()), [], [], 0)
for i in range(n):
	(a1, b1) = map(int, input().split())
	a.append(a1)
	b.append(b1)
for i in range(n):
	for j in range(n):
		if i == j:
			pass
		if a[i] == b[j]:
			ans += 1
print(ans)


teams = int(input())
g = 0
t_colors = []
for i in range(teams):
	t_colors.append([int(x) for x in input().split()])
for i in t_colors:
	g += [x[1] for x in t_colors].count(i[0])
print(g)


from itertools import permutations
n_teams = int(input())
teams = [(int(x), int(y)) for (x, y) in [input().split() for x in range(n_teams)]]
indices = permutations(list(range(n_teams)), 2)
count = 0
for (home, guest) in indices:
	if teams[home][0] == teams[guest][1]:
		count += 1
print(count)


n = int(input())
(l, r) = ([], [])
for i in range(n):
	(a, b) = map(int, input().split())
	l.append(a)
	r.append(b)
u = set(l)
chet = 0
for i in u:
	chet += r.count(i) * l.count(i)
print(chet)


n = int(input())
d = dict()
dd = dict()
bb = 0
for i in range(n):
	(n, k) = map(int, input().split())
	if n in d:
		d[n] = d[n] + 1
	else:
		d[n] = 1
	if k in dd:
		dd[k] = dd[k] + 1
	else:
		dd[k] = 1
for i in d:
	if i in dd:
		bb = bb + d[i] * dd[i]
	else:
		pass
print(bb)


dict1 = {}
dict2 = {}
n = int(input())
for i in range(n):
	(a, b) = map(int, input().split())
	if a in dict1:
		dict1[a] += 1
	else:
		dict1[a] = 1
	if b in dict2:
		dict2[b] += 1
	else:
		dict2[b] = 1
c = 0
for i in dict1:
	if i in dict2:
		c += dict1[i] * dict2[i]
print(c)


import sys
from math import ceil, log
RI = lambda : [int(x) for x in sys.stdin.readline().split()]
ri = lambda : sys.stdin.readline().strip()

def input():
	return sys.stdin.readline().strip()

def list2d(a, b, c):
	return [[c] * b for i in range(a)]

def list3d(a, b, c, d):
	return [[[d] * c for j in range(b)] for i in range(a)]

def list4d(a, b, c, d, e):
	return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]

def ceil(x, y=1):
	return int(-(-x // y))

def INT():
	return int(input())

def MAP():
	return map(int, input().split())

def LIST(N=None):
	return list(MAP()) if N is None else [INT() for i in range(N)]

def Yes():
	print('Yes')

def No():
	print('No')

def YES():
	print('Yes')

def NO():
	print('No')
INF = 10 ** 18
MOD = 10 ** 9 + 7
n = int(ri())
dic1 = {}
dic2 = {}
h = []
g = []
for i in range(n):
	(h1, g1) = RI()
	h.append(h1)
	g.append(g1)
	if h1 in dic1:
		dic1[h1] += 1
	else:
		dic1[h1] = 1
	if g1 in dic2:
		dic2[g1] += 1
	else:
		dic2[g1] = 1
cnt = 0
for i in range(n):
	cnt += dic2.get(h[i], 0) - (1 if g[i] == h[i] else 0)
print(cnt)


n = int(input())
(l_1, l_2) = ([], [])
while n:
	(hu, gu) = map(int, input().split())
	l_1.append(hu)
	l_2.append(gu)
	n -= 1
res = 0
for i in l_1:
	res += l_2.count(i)
print(res)


t = int(input())
z = t * (t - 1)
l1 = []
c = 0
for i in range(t):
	l = [int(i) for i in input().split()]
	l1.append(l)
for i in range(t):
	for j in range(t):
		if i == j:
			continue
		elif l1[i][0] == l1[j][1]:
			c += 1
print(c)


n = int(input(''))
list2 = []
count = 0
for i in range(n):
	list1 = list(map(int, input().split()))
	list2.append(list1)
for i in list2:
	l = i[0]
	for j in list2:
		if l == j[1]:
			count += 1
		else:
			continue
print(count)


m = int(input())
count = 0
n = []
for i in range(m):
	d = list(map(int, input().split()))[:2]
	n.append(d)
for j in range(1):
	if j == 0:
		for l in range(len(n)):
			for k in range(len(n)):
				if n[l][0] == n[k][1]:
					count = count + 1
print(count)


home = []
guest = []
for i in range(int(input())):
	(x, y) = map(int, input().split())
	home.append(x)
	guest.append(y)
count = 0
for i in home:
	count += guest.count(i)
print(count)


n = int(input())
b = []
c = []
for i in range(n):
	k = input().split()
	b.append(k[0])
	c.append(k[1])
sum = 0
for i in range(n):
	for j in range(n):
		if b[i] == c[j]:
			sum += 1
print(sum)


(h, g) = ([], [])
for _ in range(int(input())):
	(a, b) = map(int, input().split())
	h.append(a)
	g.append(b)
print(sum((h.count(x) for x in g)))


e = []
f = []
c = 0
for _ in range(int(input())):
	(a, b) = map(int, input().split())
	e.append(a)
	f.append(b)
for i in e:
	for j in f:
		if i == j:
			c += 1
print(c)


c = int(input())
h = []
g = []
res = 0
for i in range(c):
	b = list(map(int, input().split(' ')))
	h.append(b[0])
	g.append(b[1])
for i in range(c):
	for j in range(c):
		if h[i] == g[j]:
			res += 1
print(res)


n = int(input())
h = []
a = []
for i in range(n):
	(hi, ai) = [int(i) for i in input().split()]
	h.append(hi)
	a.append(ai)
num = 0
for i in range(n):
	num += sum([h[i] == j for j in a])
print(num)


n = int(input())
k = 0
res1 = []
res2 = []
p1 = []
p2 = []
for i in range(n):
	m = input().split()
	p1.append(m[0])
	p2.append(m[1])
for i in range(n):
	for j in range(n):
		if j != i:
			res1.append([p1[i], p2[j]])
for j in range(n):
	for i in range(n):
		if j != i:
			res2.append([p2[j], p1[i]])
for i in range(len(res1)):
	if res1[i][0] == res1[i][1]:
		k += 1
print(k)


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


def function1(a, b):
	count = 0
	for i in range(len(a)):
		count += b.count(a[i])
	return count

def main():
	n = int(input())
	home = [0 for i in range(n)]
	nothome = [0 for i in range(n)]
	for i in range(n):
		(home[i], nothome[i]) = map(int, input().split())
	print(function1(home, nothome))
main()


n = int(input())
home = [None] * n
guest = [None] * n
for i in range(n):
	(a, b) = map(int, input().split())
	(home[i], guest[i]) = (a, b)
ans = 0
for i in range(n):
	for j in range(i + 1, n):
		if home[i] == guest[j]:
			ans += 1
		if home[j] == guest[i]:
			ans += 1
print(ans)


from collections import defaultdict
n = int(input())
x = []
z = defaultdict(lambda : 0)
for j in range(n):
	(a, b) = map(int, input().split())
	x.append(b)
	z[a] += 1
an = 0
for j in x:
	an += z[j]
print(an)


n = [int(i) for i in input().split()][0]
home = [0] * n
guest = [0] * n
ans = 0
for i in range(n):
	(home[i], guest[i]) = [int(i) for i in input().split()]
for i in range(n):
	for j in range(i + 1, n):
		if home[i] == guest[j]:
			ans += 1
		if home[j] == guest[i]:
			ans += 1
print(ans)


n = int(input())
A = []
B = []
count = 0
while n > 0:
	(a, b) = input().split()
	A.append(a)
	B.append(b)
	n -= 1
for i in A:
	for j in B:
		if i == j:
			count += 1
print(count)


import sys
inf = float('inf')
(mod, MOD) = (1000000007, 998244353)
from collections import deque, Counter, OrderedDict, defaultdict
from heapq import nsmallest, nlargest, heapify, heappop, heappush, heapreplace
from math import ceil, floor, log, sqrt, factorial, pow, pi, gcd, log10, atan, tan

def get_array():
	return list(map(int, sys.stdin.readline().strip().split()))

def get_ints():
	return map(int, sys.stdin.readline().strip().split())

def input():
	return sys.stdin.readline().strip()
n = int(input())
Arr = []
for i in range(n):
	(a, b) = get_ints()
	Arr.append((a, b))
count = 0
for i in range(n):
	for j in range(n):
		if i == j:
			continue
		elif Arr[i][0] == Arr[j][1]:
			count += 1
print(count)


n = int(input())
h = []
g = []
for i in range(n):
	s = input().split()
	h.append(s[0])
	g.append(s[1])
c = 0
for i in h:
	c += g.count(i)
print(c)


a = int(input())
k = 0
d = []
v = []
for i in range(a):
	b = input().split()
	d.append(b[0])
	v.append(b[1])
for i in range(a):
	for j in range(a):
		if d[i] == v[j]:
			k += 1
print(k)


n = int(input())
h = []
a = []
for i in range(n):
	(c, d) = input().split()
	h.append(int(c))
	a.append(int(d))
cnt = 0
for x in h:
	for y in a:
		if x == y:
			cnt += 1
print(cnt)


ha = []
count = 0
from itertools import permutations
n = int(input())
l = [i for i in range(1, n + 1)]
perm = list(permutations(l, 2))
for i in range(n):
	ha.append(input().split())
for term in perm:
	if ha[term[0] - 1][0] == ha[term[1] - 1][1]:
		count += 1
print(count)


n = int(input())
a = []
for i in range(n):
	a.append(list(map(int, input().split())))
count = 0
for j1 in range(1):
	for i1 in range(n):
		for j2 in range(1, 2):
			for i2 in range(n):
				if a[i1][j1] == a[i2][j2]:
					count += 1
print(count)


import math
INF = 1000000000.0

def main():
	n = int(input())
	cnt = 0
	g = [0] * 200
	a = []
	for i in range(n):
		row = list(map(int, input().split()))
		a.append(row)
		g[a[i][1]] += 1
	for i in range(n):
		cnt += g[a[i][0]]
	print(cnt)
main()


__author__ = 'Utena'
n = int(input())
s = [list(map(int, input().split())) for k in range(n)]
t = 0
for i in range(n):
	for j in range(n):
		if s[i][0] == s[j][1]:
			t += 1
print(t)


teamnumber = int(input())
host = []
guest = []
for i in range(teamnumber):
	(a, b) = map(int, input().split())
	host.append(a)
	guest.append(b)
outcome = 0
for i in host:
	outcome += guest.count(i)
print(outcome)


x = int(input())
m = []
n = []
k = 0
for i in range(x):
	s = input().split()
	m.append(int(s[0]))
	n.append(int(s[1]))
for i in range(x):
	for j in range(x):
		if m[i] == n[j]:
			k += 1
print(k)


n = int(input())
d = {}
for i in range(n):
	(h, a) = map(int, input().split(' '))
	d[i] = (h, a)
l = list(d.values())
answer = 0
for i in range(n * n):
	if l[i // n][0] == l[i % n][1]:
		answer += 1
print(answer)


n = int(input())
home = list()
guest = list()
for i in range(n):
	(h, a) = [int(x) for x in input().split()]
	home.append(h)
	guest.append(a)
r = 0
for i in guest:
	r += home.count(i)
print(r)


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


n = int(input())
l = []
for i in range(n):
	l.append(tuple(map(int, input().split())))
c = 0
for t in l:
	for x in l:
		if t[1] == x[0]:
			c += 1
print(c)


n = int(input())
(home, guest) = ([], [])
for _ in range(n):
	inpt = input().split()
	home.append(inpt[0])
	guest.append(inpt[1])
count = 0
for i in range(n):
	count += home.count(guest[i]) - int(home[i] == guest[i])
print(count)


class Team:

	def __init__(self, h, g):
		self.home = h
		self.guest = g
n = int(input())
forms = []
for _ in range(n):
	(home, guest) = map(int, input().split())
	forms.append(Team(home, guest))
count = 0
for i in range(n - 1):
	for j in range(i + 1, n):
		if forms[i].home == forms[j].guest:
			count += 1
		if forms[i].guest == forms[j].home:
			count += 1
print(count)


n = int(input())
mat = []
for i in range(n):
	mat.append(list(map(int, input().split())))
cnt = 0
for x in range(len(mat)):
	for y in range(len(mat)):
		if x != y:
			if mat[x][0] == mat[y][1]:
				cnt += 1
print(cnt)


n = int(input())
b = []
count = 0
for i in range(n):
	(h, a) = map(int, input().split())
	b.append([h, a])
for i in range(n):
	c = b[:]
	d = b[i]
	del c[i]
	e = []
	for j in range(n - 1):
		e.append(c[j][1])
	count += e.count(d[0])
print(count)


n = int(input())
A = []
num = 0
for i in range(n):
	B = [int(x) for x in input().split()]
	A.append(B[0])
	A.append(B[1])
for i in range(n):
	for j in range(n):
		if j != i and A[2 * i] == A[2 * j + 1]:
			num += 1
print(num)


n = int(input())
teams = []
i = 0
while i < n:
	s = list(map(int, input().split()))
	teams.append(s)
	i = i + 1
count = 0
i = 0
while i < n:
	j = 0
	while j < n:
		if j != i:
			if teams[i][0] == teams[j][1]:
				count = count + 1
		j = j + 1
	i = i + 1
print(count)


n = int(input())
a = n * [0]
b = n * [0]
for i in range(n):
	(a[i], b[i]) = [int(i) for i in input().split()]
t = 0
for i in range(n):
	z = a[i]
	for j in range(n):
		if z == b[j]:
			t = t + 1
print(t)


n = int(input())
s = [input().split() for _ in range(n)]
print(sum((s[i][0] == s[j][1] for i in range(n) for j in range(n) if i != j)))


n = int(input())
d = []
for x in range(n):
	(a, b) = map(int, input().split())
	d.append(a)
	d.append(b)
s = 0
for x in range(n):
	for y in range(n):
		if d[2 * x] == d[2 * y + 1] and x != y:
			s += 1
print(s)


import sys
input = sys.stdin.readline
home = []
away = []
n = input()
n = int(n)
for i in range(0, n):
	arr = [int(x) for x in input().split()]
	away.append(arr[1])
	home.append(arr[0])
counter = 0
for i in range(0, n):
	for j in range(0, n):
		if i == j:
			continue
		elif home[i] == away[j]:
			counter += 1
print(counter)


n = int(input())
l = []
i = 0
while i < n:
	s = list(map(int, input().split()))
	l.append(s)
	i += 1
ans = 0
for i in l:
	for j in l:
		if i[0] == j[1]:
			ans += 1
print(ans)


n = int(input())
ho = []
gu = []
while n != 0:
	(h, g) = map(int, input().split())
	ho.append(h)
	gu.append(g)
	n = n - 1
count = 0
for i in range(0, len(ho)):
	for j in range(0, len(gu)):
		if ho[i] == gu[j]:
			count = count + 1
print(count)


n = int(input())
m1 = []
m2 = []
for i in range(n):
	(f1, f2) = map(int, input().split())
	m1.append(f1)
	m2.append(f2)
cnt = 0
for f in m1:
	cnt += m2.count(f)
print(cnt)


n = int(input())
l1 = []
l2 = []
count = 0
l3 = []
for i in range(n):
	(a, b) = list(map(int, input().split()))
	l1.append(a)
	l2.append(b)
for i in range(len(l1)):
	for j in range(len(l1)):
		if l1[i] == l2[j]:
			count += 1
			l3.append(count)
if len(l3) == 0:
	print(0)
else:
	print(max(l3))


n = int(input())
u = []
for i in range(n):
	(a, b) = map(int, input().split())
	u.append([a, b])
qtd = 0
for H in u:
	for G in u:
		if H[0] == G[1]:
			qtd += 1
print(qtd)


a = []
b = []
r = 0
for i in range(int(input())):
	(x, y) = map(int, input().split())
	a.append(x)
	b.append(y)
m = dict()
for i in a:
	m[i] = m.get(i, 0) + 1
for i in b:
	if i in a:
		r = r + m.get(i)
print(r)


a = int(input())
b = []
c = 0
for x in range(a):
	b.append(list(map(int, input().split())))
for y in range(a):
	for z in range(a):
		if b[y][0] == b[z][1]:
			c += 1
print(c)


n = int(input())
lis = []
res = 0
for i in range(n):
	li = [int(num) for num in input().strip().split()][:n]
	lis.extend(li)
del li
for i in range(0, len(lis), 2):
	for j in range(1, len(lis), 2):
		if i + 1 == j:
			continue
		elif lis[i] == lis[j]:
			res += 1
print(res)


n = int(input())
games = 0
hu = []
gu = []
for i in range(0, n):
	(h, g) = map(int, input().split())
	hu.append(h)
	gu.append(g)
for x in range(0, n):
	for y in range(0, n):
		if hu[x] == gu[y]:
			games += 1
print(games)


x = int(input())
home_uniform = []
guest_uniform = []
answer = 0
for i in range(x):
	(a, b) = [int(i) for i in input().split()]
	home_uniform.append(a)
	guest_uniform.append(b)
for i in home_uniform:
	answer += guest_uniform.count(i)
print(answer)


n = int(input())
l1 = []
for _ in range(n):
	a = [int(i) for i in input().split()]
	l1.append(a)
l2 = []
x = 0
for i in range(n):
	l2.append(l1[i][1])
for i in range(n):
	x += l2.count(l1[i][0])
print(x)


n = int(input())
v1 = []
v2 = []
for i in range(n):
	(x, y) = map(int, input().split())
	v1.append(x)
	v2.append(y)
an = 0
for i in v1:
	for j in v2:
		if i == j:
			an += 1
print(an)


h = []
g = []
for _ in range(int(input())):
	(t1, t2) = list(map(int, input().split()))
	h.append(t1)
	g.append(t2)
count = 0
for i in range(len(h)):
	for j in range(len(g)):
		if h[i] == g[j]:
			count += 1
print(count)


n = int(input())
hlist = []
glist = []
for i in range(n):
	(h, g) = input().split()
	h = int(h)
	g = int(g)
	hlist.append(h)
	glist.append(g)
count = 0
for j in range(n):
	chk = hlist[j]
	for k in range(n):
		if k == j:
			continue
		if chk == glist[k]:
			count += 1
print(count)


integer = input()
integer = int(integer)
i = 0
m = 0
n = 0
t = 0
list1 = []
list2 = []
while i < integer:
	(x, y) = input().split(' ')
	x = int(x)
	y = int(y)
	list1.append(x)
	list2.append(y)
	i = i + 1
while m < len(list1):
	while n < len(list2):
		if m != n:
			if list1[m] == list2[n]:
				t = t + 1
			n = n + 1
		else:
			n = n + 1
	n = 0
	m = m + 1
print(t)


a = []
b = []
n = int(input())
for i in range(n):
	s = input().split()
	a.append(int(s[0]))
	b.append(int(s[1]))
ans = int(0)
for i in range(n):
	for j in range(n):
		if i != j and b[i] == a[j]:
			ans = ans + 1
print(ans)


a = int(input())
emp = []
for i in range(a):
	b = input().split()
	emp.append([int(b[0]), int(b[1])])
count = 0
for j in range(len(emp)):
	for k in range(len(emp)):
		if emp[j][0] == emp[k][1]:
			count += 1
print(count)


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


n = int(input())
home_color = []
guest_color = []
game = []
count = 0
for i in range(n):
	game = input().split()
	home_color.append(game[0])
	guest_color.append(game[1])
for i in home_color:
	count = count + guest_color.count(i)
print(count)


x = int(input())
y = []
q = 0
for i in range(x):
	y.append(input().split())
l = [int(i) for (i, j) in y]
r = [int(j) for (i, j) in y]
for i in l:
	q += r.count(i)
print(q)


itr = int(input())
uniform = []
count = 0
for i in range(0, itr):
	row = list(map(int, input().split(' ')))
	uniform.append(row)
for i in range(0, itr):
	for j in range(0, itr):
		if i == j:
			continue
		elif uniform[i][0] == uniform[j][1]:
			count = count + 1
print(count)


def swaprows(M, r1, r2):
	(M[r1], M[r2]) = (M[r2], M[r1])
	pass
n = int(input())
c = 0
matrix = [[int(x) for x in input().split()] for i in range(n)]
for i in range(n):
	swaprows(matrix, 0, i)
	for j in range(1, n):
		if matrix[0][0] == matrix[j][1]:
			c += 1
print(c)


n = int(input())
ar = []
for i in range(n):
	ar.append(list(map(int, input().split())))
cnt = 0
for i in range(n):
	for j in range(n):
		if i == j:
			continue
		elif ar[i][0] == ar[j][1]:
			cnt += 1
print(cnt)


n = int(input())
k = 0
lh = []
la = []
for i in range(n):
	(h, a) = map(int, input().split())
	lh.append(h)
	la.append(a)
for i in range(n):
	hi = lh[i]
	k += la.count(hi)
print(k)


n = int(input())
multi_list = [[0 for col in range(2)] for row in range(n)]
for row in range(n):
	temp = list(input().split())
	for col in range(2):
		multi_list[row][col] = temp[col]
counter = 0
for row in range(n):
	for comparedRow in range(n):
		if multi_list[row][0] == multi_list[comparedRow][1]:
			counter += 1
print(counter)


n = int(input())
k = []
p = []
c = 0
d = 0
for i in range(n):
	l = list(map(int, input().split()))
	k.append(l[0])
	p.append(l[1])
for i in range(n):
	c += k.count(p[i])
print(c)


n = int(input())
h = []
a = []
count = 0
for i in range(n):
	(hi, ai) = input().split()
	(hi, ai) = (int(hi), int(ai))
	h.append(hi)
	a.append(ai)
for i in range(n):
	for j in range(n):
		if j != i and h[i] == a[j]:
			count += 1
print(count)


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


N = int(input())
m = []
for K in range(N):
	Part = input()
	Part = Part.split()
	Part[0] = int(Part[0])
	Part[1] = int(Part[1])
	m.append(Part)
Cont = 0
for J in range(N):
	for I in range(N):
		if m[J][0] == m[I][1]:
			Cont += 1
print(Cont)


n = int(input())
home = []
guest = []
for _ in range(n):
	tmp = list(map(int, input().split()))
	home.append(tmp[0])
	guest.append(tmp[1])
nbr = 0
for h in home:
	nbr += guest.count(h)
print(nbr)


from itertools import permutations
my_dict = {i: input().split() for i in range(int(input()))}
counter = 0
for each_case in permutations(my_dict.keys(), 2):
	if my_dict[each_case[0]][0] == my_dict[each_case[1]][1]:
		counter += 1
print(counter)


x = 0
n = int(input())
lt = []
(lhome, lgest) = ([], [])
for i in range(n):
	l = input().split()
	(h, g) = (l[0], l[1])
	lhome.append(l[0])
	lgest.append(l[1])
for i in iter(lhome):
	for j in iter(lgest):
		if i == j:
			x += 1
print(x)


x = []
z = []
for i in range(int(input())):
	(n, m) = input().split()
	x.append(n)
	z.append(m)
a = 0
for j in x:
	a += z.count(j)
print(a)


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


n = int(input())
a = []
c = 0
for x in range(n):
	a.append(input().split())
for x in range(n):
	for y in range(n):
		if a[x][0] == a[y][1]:
			c += 1
print(c)


def read_tokens():
	return input().strip().split(' ')

def read_ints():
	return [int(s) for s in read_tokens()]

def compute(arr):
	count = 0
	for our in arr:
		for their in arr:
			if our != their:
				if our[0] == their[1]:
					count += 1
	return count
(T,) = read_ints()
forma = []
for _ in range(T):
	(a, b) = read_ints()
	forma.append((a, b))
ans = compute(forma)
print(ans)


n = int(input())
x = [0] * n
y = [0] * n
for i in range(0, n):
	(x[i], y[i]) = map(int, input().split())
s = 0
for i in x:
	s += y.count(i)
print(s)


n = int(input())
host = []
guest = []
for i in range(n):
	temp = input().split()
	host.append(temp[0])
	guest.append(temp[1])
ans = 0
for i in host:
	ans += guest.count(i)
print(ans)


n = int(input())
a = []
b = []
for _ in range(n):
	x = input().split()
	a.append(x[0])
	b.append(x[1])
coun = 0
for i in a:
	for j in b:
		if i == j:
			coun += 1
print(coun)


def solve(number_team):
	home = []
	outside = []
	for i in range(number_team):
		game_play = list(map(int, input().split(' ')))
		home.append(game_play[0])
		outside.append(game_play[1])
	count = 0
	for x in range(len(home)):
		for y in range(len(outside)):
			if home[x] == outside[y]:
				count += 1
	print(count)
solve(int(input()))


n = int(input())
arr = []
for i in range(n):
	(a, b) = map(int, input().split())
	arr.append([a, b])
counter = 0
for i in range(len(arr)):
	for j in range(len(arr)):
		if i != j and arr[i][1] == arr[j][0]:
			counter += 1
print(counter)


teams = int(input())
uniformes_home = []
uniformes_guest = []
contador = 0
for i in range(teams):
	equipo = list(map(int, input().split()))
	(home, guest) = equipo
	uniformes_home.append(home)
	uniformes_guest.append(guest)
for i in uniformes_home:
	contador += uniformes_guest.count(i)
print(contador)


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


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


n = int(input())
s_a = list(str())
s_b = list(str())
value = 0
for i in range(n):
	(a, b) = list(map(int, input().split()))
	s_a.append(a)
	s_b.append(b)
for i in range(n):
	for j in range(n):
		if s_b[i] == s_a[j]:
			value += 1
print(value)


n = int(input())
away = []
home = []
res = 0
for i in range(n):
	temp = input().split()
	home.append(int(temp[0]))
	away.append(int(temp[1]))
for i in home:
	res = res + away.count(i)
print(res)


t = int(input())
main = []
ans = 0
for _ in range(t):
	main.append(input().split())
for i in main:
	for x in main:
		if i[0] == x[1]:
			ans += 1
print(ans)


import sys
input = sys.stdin.readline

def main():
	from collections import defaultdict
	a_dd = defaultdict(int)
	b_dd = defaultdict(int)
	for _ in range(int(input())):
		(a, b) = map(int, input().split())
		a_dd[a] += 1
		b_dd[b] += 1
	ans = 0
	for (key, value) in a_dd.items():
		ans += value * b_dd[key]
	print(ans)
main()


n = int(input())
L = []
for i in range(n):
	L.append(input().split())

def Rec(s):
	if s == n - 1:
		return 0
	else:
		(a, b) = L[s]
		ilova = 0
		for i in range(s + 1, n):
			if L[i][0] == b:
				ilova += 1
			if L[i][1] == a:
				ilova += 1
		return ilova + Rec(s + 1)
print(Rec(0))


n = int(input())
m = [0 for i in range(n)]
m1 = [0 for i in range(n)]
count = 0
for i in range(n):
	(m[i], m1[i]) = map(int, input().split())
for i in range(n):
	for j in range(n):
		if m[i] == m1[j]:
			count += 1
print(count)


x = int(input())
arr = []
for i in range(x):
	arr.append(list(map(int, input().split())))
c = 0
for l in range(x):
	for v in range(x):
		if arr[l][0] == arr[v][1]:
			c += 1
print(c)


while True:
	n = int(input())
	if n >= 2 and n <= 30:
		break
home = []
away = []
for i in range(n):
	(h, a) = input().split(' ')
	home.append(h)
	away.append(a)
comp = 0
for j in range(n):
	for k in range(n):
		if j != k and int(home[j]) == int(away[k]):
			comp += 1
print(comp)


n = int(input())
a = 0
l = [0] * n
for i in range(n):
	l[i] = list(map(int, input().split()))
for i in range(n):
	for z in range(i + 1, n, 1):
		if l[i][0] == l[z][1]:
			a += 1
		if l[i][1] == l[z][0]:
			a += 1
print(a)


n = int(input())
a = [[0] * n for _ in range(n)]
for i in range(n):
	a[i] = [int(j) for j in input().split()]
count = 0
for i in range(n):
	for j in range(n):
		if a[i][0] == a[j][1]:
			count += 1
print(count)


li = []
for i in range(int(input())):
	m = list(map(int, input().split()))
	li.append(m)
sm = 0
for i in range(len(li)):
	for j in range(len(li)):
		if i == j:
			pass
		elif li[i][0] == li[j][1]:
			sm += 1
print(sm)


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


n = int(input())
uniforms = []
for i in range(n):
	uniforms.append([int(x) for x in input().split()])
result = 0
for i in range(n):
	for j in range(i + 1, n):
		if uniforms[i][0] == uniforms[j][1]:
			result += 1
		if uniforms[i][1] == uniforms[j][0]:
			result += 1
print(result)


def solve():
	n = int(input())
	m1 = dict()
	m2 = dict()
	ans = 0
	for i in range(n):
		(a, b) = [int(s) for s in input().split()]
		if a in m2:
			ans += m2[a]
		if b in m1:
			ans += m1[b]
		m1[a] = m1.get(a, 0) + 1
		m2[b] = m2.get(b, 0) + 1
	print(ans)
solve()


n = int(input())
h = []
l = []
for i in range(n):
	s = list(map(int, input().split(' ')))
	h.append(s[0])
	l.append(s[1])
o = 0
for i in range(n):
	o += l.count(h[i])
print(o)


n = int(input())
i = 0
host_uniform = []
guest_uniform = []
while i < n:
	team_uniform = str(input()).split(' ')
	host_uniform.append(team_uniform[0])
	guest_uniform.append(team_uniform[1])
	i = i + 1
i = 0
j = 0
while i < n:
	k = 0
	while k < n:
		if host_uniform[i] == guest_uniform[k]:
			j = j + 1
			k = k + 1
		else:
			k = k + 1
	i = i + 1
print(str(j))


n = int(input())
home = []
guest = []
for i in range(n):
	(h, g) = input().split(' ')
	home.append(h)
	guest.append(g)
c = 0
for i in home:
	for j in guest:
		if i == j:
			c += 1
print(c)


n = int(input())
games = []
for _ in range(n):
	(h, a) = [int(x) for x in input().split()]
	games.append((h, a))
count = 0
for i in range(n):
	for j in range(n):
		if i == j:
			continue
		if games[i][0] == games[j][1]:
			count += 1
print(count)


n = int(input())
i = 0
l1 = []
l2 = []
while i < n:
	(ai, bi) = map(int, input().split(' '))
	l1.append(ai)
	l2.append(bi)
	i = i + 1
k = 0
for i in l1:
	for j in l2:
		if i == j:
			k = k + 1
		else:
			continue
print(k)


n = int(input())
a = []
for i in range(n):
	a.append([int(x) for x in input().split()])
counter = 0
for l in a:
	h = l[0]
	for t in a:
		if l == t:
			continue
		if h == t[1]:
			counter += 1
print(counter)


n = int(input())
timeDaCasa = []
timeVisitante = []
contador = 0
while n != 0:
	(h1, a1) = map(int, input().split())
	timeDaCasa.append(h1)
	timeVisitante.append(a1)
	n -= 1
for i in timeDaCasa:
	for j in timeVisitante:
		if j == i:
			contador += 1
print(contador)


N = int(input())
hosts = []
guests = []
for i in range(0, N):
	(a, b) = map(int, input().split())
	hosts.append(a)
	guests.append(b)
cnt = 0
for i in range(0, N):
	for j in range(0, N):
		if i != j and hosts[i] == guests[j]:
			cnt += 1
print(cnt)


n = int(input())
a = []
count = 0
for x in range(n):
	a.append(tuple(input().split()))
for x in range(n):
	for y in range(n):
		if a[x][0] == a[y][1] and x != y:
			count += 1
print(count)


a = int(input())
lst1 = []
lst2 = []
for i in range(a):
	lst = input().split()
	lst1.append(lst[0])
	lst2.append(lst[1])
m = 0
for j in lst1:
	for t in lst2:
		if j == t:
			m += 1
print(m)


n = int(input())
matches = n * (n - 1)
total = [0] * n
z = form = game = conflict = 0
for i in range(n):
	total[i] = list(map(int, input().split()))
for i in range(n):
	for j in range(n):
		game += i + 1
		hozyaeva = total[i]
		gosti = total[j]
		if hozyaeva[0] == gosti[1]:
			conflict += 1
print(conflict)


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)


from collections import defaultdict

def compute_color_conflicts(n: int) -> int:
	freq_map_home = defaultdict(int)
	freq_map_away = defaultdict(int)
	for _ in range(n):
		(home_color, away_color) = map(int, input().strip().split())
		freq_map_home[home_color] += 1
		freq_map_away[away_color] += 1
	conflict_count = 0
	for (key, value) in freq_map_home.items():
		conflict_count += value * freq_map_away[key]
	return conflict_count

def main():
	print(compute_color_conflicts(int(input().strip())))
main()


n = int(input())
cnt = 0
hm = [None] * n
gu = [None] * n
for i in range(n):
	(hm[i], gu[i]) = [int(x) for x in input().split()]
for i in range(n):
	for j in range(n):
		if hm[i] == gu[j]:
			cnt += 1
print(cnt)


n = int(input())
a = []
for i in range(n):
	s = input().split(' ')
	a.append((int(s[0]), int(s[1])))
out = 0
for i in range(n):
	for j in range(i, n):
		if a[i][0] == a[j][1]:
			out += 1
		if a[i][1] == a[j][0]:
			out += 1
print(out)


n = int(input())
count = 0
var = [[0] * 2] * 30
for i in range(n):
	var[i] = input().split(' ')
for h in range(n):
	for g in range(n):
		if g != h:
			if var[h][0] == var[g][1]:
				count += 1
print(count)


import sys

def fastio():
	from io import StringIO
	from atexit import register
	global input
	sys.stdin = StringIO(sys.stdin.read())
	input = lambda : sys.stdin.readline().rstrip('\r\n')
	sys.stdout = StringIO()
	register(lambda : sys.__stdout__.write(sys.stdout.getvalue()))
fastio()

def debug(*var, sep=' ', end='\n'):
	print(*var, file=sys.stderr, end=end, sep=sep)
INF = 10 ** 20
MOD = 10 ** 9 + 7
I = lambda : list(map(int, input().split()))
from math import gcd
from math import ceil
from collections import defaultdict as dd, Counter
from bisect import bisect_left as bl, bisect_right as br
(n,) = I()
ans = 0
l = []
for i in range(n):
	l.append(I())
for i in range(n):
	for j in range(n):
		if l[i][0] == l[j][1]:
			ans += 1
print(ans)


x = 0
c = []
d = []
for i in range(int(input())):
	(a, b) = map(int, input().split())
	c.append(a)
	d.append(b)
for q in range(len(c)):
	for w in range(len(d)):
		if c[q] == d[w]:
			x += 1
print(x)


n = int(input())
(a, b) = ([], [])
for _ in range(n):
	lists = list(map(int, input().rstrip().split()))
	a.append(lists[0])
	b.append(lists[1])
total = 0
for i in a:
	total += b.count(i)
print(total)


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


teams = int(input())
teamColors = []
for x in range(teams):
	teamColors.append([int(x) for x in input().split()])
colorChange = 0
for x in range(teams):
	for y in range(x, teams - 1):
		if teamColors[x][0] == teamColors[y + 1][1]:
			colorChange = colorChange + 1
		if teamColors[x][1] == teamColors[y + 1][0]:
			colorChange = colorChange + 1
print(colorChange)


n = int(input())
teams = [[int(x) for x in input().split(' ')] for i in range(n)]
nums = 0
for i in range(n - 1):
	for j in range(i + 1, n):
		if teams[i][0] == teams[j][1]:
			nums += 1
		if teams[i][1] == teams[j][0]:
			nums += 1
print(nums)


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


n = int(input())
h = [0] * n
a = [0] * n
for i in range(n):
	(hi, ai) = list(map(int, input().split()))
	h[i] = hi
	a[i] = ai
counter = 0
for i in range(n):
	for j in range(n):
		if h[i] == a[j] and i != j:
			counter += 1
print(counter)


number_of_teams = int(input())
teams_with_color = []
count_matches = 0
for n in range(number_of_teams):
	read_line = str(input())
	home_and_guest_color = [int(s) for s in read_line.split(' ')]
	teams_with_color.append(home_and_guest_color)
for n in range(number_of_teams):
	team = teams_with_color[n]
	for t in range(number_of_teams):
		team_to_compare = teams_with_color[t]
		if team != team_to_compare:
			if team[0] == team_to_compare[1]:
				count_matches += 1
print(count_matches)


n = int(input())
a = 0
h = 0
m = 0
b = []
c = []
for i in range(n):
	(h, a) = map(int, input().split())
	b.append(h)
	c.append(a)
for x in b:
	for y in c:
		if x == y:
			m += 1
print(m)


n = int(input())
d1 = list()
d2 = list()
for i in range(n):
	x = list(map(int, input().split()))
	d1.append(x[0])
	d2.append(x[1])
sum = 0
for i in range(len(d1)):
	for j in range(len(d2)):
		if d1[i] == d2[j]:
			sum += 1
print(sum)


a = dict()
b = dict()
n = int(input())
for i in range(n):
	(h, g) = map(int, input().split())
	a[h] = a.get(h, 0) + 1
	b[g] = b.get(g, 0) + 1
ans = 0
for i in b.keys():
	if i in a:
		ans += b[i] * a[i]
print(ans)


p = int(input())
home = []
guest = []
for i in range(p):
	(m, n) = [int(x) for x in input().split()]
	home.append(m)
	guest.append(n)
k = 0
for i in range(p):
	k += guest.count(home[i])
print(k)


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


t = int(input())
a = []
b = []
for i in range(0, t):
	(n, m) = map(int, input().strip().split())
	a.append(n)
	b.append(m)
c = 0
for i in a:
	c += b.count(i)
print(c)


import sys
from collections import defaultdict

def read_arr(dtype=int):
	return [dtype(c) for c in sys.stdin.readline().strip().split()]
(host, guest) = (defaultdict(int), defaultdict(int))
n = read_arr()[0]
for _ in range(n):
	(h, g) = read_arr()
	host[h] += 1
	guest[g] += 1
total = 0
for (k, v) in host.items():
	total += v * guest[k]
print(total)


import sys
from collections import Counter
n = int(input())
arrayHome = []
arrayGuest = []
for _ in range(n):
	(a, b) = map(int, sys.stdin.readline().split())
	arrayHome.append(a)
	arrayGuest.append(b)
dict1 = Counter(arrayGuest)
ans = 0
for x in arrayHome:
	ans += dict1[x]
print(ans)


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


n = int(input())
l = []
for _ in range(n):
	l.append(list(map(int, input().split())))
tot = 0
for x in range(n):
	lista = list(range(n))
	lista.remove(x)
	for y in lista:
		if l[x][0] == l[y][1]:
			tot += 1
print(tot)


no = int(input())
home = []
away = []
for i in range(no):
	(h, a) = map(int, input().split())
	home.append(h)
	away.append(a)
count = 0
for i in home:
	for j in away:
		if i == j:
			count += 1
print(count)


n = int(input())
i = 0
x = 0
yifu = []
while i < n:
	i = i + 1
	yifu.append(input().split())
for k in range(0, n):
	for j in range(0, n):
		if yifu[k][0] == yifu[j][1]:
			x += 1
print(x)


n = int(input())
(home, guest) = ([], [])
for i in range(n):
	(a, b) = map(int, input().split())
	home.append(a)
	guest.append(b)
print(sum((guest.count(h) for h in home)))


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())
h = [None for i in range(n)]
a = [None for i in range(n)]
for i in range(n):
	(p, q) = list(map(int, input().split()))
	h[i] = p
	a[i] = q
ans = 0
for i in range(n):
	for j in range(n):
		if i != j and h[i] == a[j]:
			ans = ans + 1
print(ans)


n = int(input())
(a, h) = ([], [])
for _ in range(n):
	(ha, aa) = map(int, input().split())
	h.append(ha)
	a.append(aa)
ans = 0
for i in range(len(a)):
	for j in range(len(h)):
		if i != j and a[i] == h[j]:
			ans += 1
print(ans)


n = int(input())
uniforms = [[0, 0] for i in range(n)]
for i in range(n):
	(h, a) = map(int, input().split())
	uniforms[i][0] = h
	uniforms[i][1] = a
count = 0
for i in range(n):
	t = uniforms[i][1]
	for j in range(n):
		if i == j:
			continue
		if uniforms[j][0] == t:
			count += 1
print(count)


n = int(input())
shirts = []

def check(index, end, shirts):
	result = 0
	if end >= len(shirts):
		return 0
	else:
		if shirts[index][0] == shirts[end][1]:
			result += 1
		if shirts[index][1] == shirts[end][0]:
			result += 1
		return result + check(index, end + 1, shirts)
for i in range(n):
	shirts.append(list(input().split()))
result = 0
for i in range(n):
	result += check(i, i + 1, shirts)
print(result)


n = int(input())
times = []
for i in range(n):
	(home, guest) = map(int, input().split())
	times.append([home, guest])
cont = 0
for i in range(n):
	for j in range(n):
		if i != j and times[i][0] == times[j][1]:
			cont += 1
print(cont)


n = int(input())
line = [0] * n
for i in range(n):
	line[i] = input().split()
line.sort()
summ = 0
for i in range(n):
	for j in range(n):
		if line[j][1] == line[i][0]:
			summ += 1
print(summ)


n = int(input())
a = [None] * n
b = [None] * n
count = 0
for i in range(n):
	(x, y) = map(int, input().split())
	a[i] = x
	b[i] = y
for i in range(n):
	for j in range(n):
		if a[i] == b[j] and i != j:
			count += 1
print(count)


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(''))
lis = []
for i in range(n):
	integer_string = input('')
	inte = list(integer_string.split(' '))
	lis.append(inte)
c = 0
for j in range(n):
	for k in range(n):
		if j != k:
			if lis[j][0] == lis[k][1]:
				c += 1
			else:
				continue
		else:
			continue
print(c)


def create_matches(teams):
	matches = []
	for k in range(len(teams)):
		(teams[k], teams[0]) = (teams[0], teams[k])
		for i in range(1, len(teams)):
			matches.append([teams[0], teams[i]])
	return matches

def host_guest_switches(matches):
	count = 0
	for match in matches:
		team_1 = match[0]
		team_2 = match[1]
		if team_1[0] == team_2[1]:
			count += 1
	return count

def main():
	n = int(input())
	teams = []
	for i in range(n):
		teams.append([int(i) for i in input().split()])
	matches = create_matches(teams)
	count = host_guest_switches(matches)
	print(count)
main()


n = int(input())
a = []
ct = 0
for i in range(n):
	a.append([int(x) for x in input().split()])
for i in range(n - 1):
	for j in range(i + 1, n):
		if a[i][1] == a[j][0]:
			ct += 1
		if a[i][0] == a[j][1]:
			ct += 1
print(ct)


n = int(input())
count = 0
l = []
for i in range(n):
	l.append(list(map(int, input().split())))
home = []
away = []
for i in l:
	home.append(i[0])
	away.append(i[1])
for i in home:
	count += away.count(i)
print(count)


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


n = int(input())
(l, p) = ([], [])
while n > 0:
	n -= 1
	(a, b) = list(map(int, input().split()))
	l.append(a)
	p.append(b)
ans = 0
for i in l:
	ans += p.count(i)
print(ans)


t = int(input())
c = 0
l = []
for _ in range(t):
	l.append(list(map(int, input().split())))
for x in l:
	for y in l:
		if l.index(x) == l.index(y):
			continue
		if x[0] == y[1]:
			c += 1
print(c)


a = int(input())
c = []
d = []
x = 0
for i in range(0, a):
	b = input().split()
	c.append(b[0])
	d.append(b[1])
for i in range(0, a):
	for y in range(0, a):
		if c[i] == d[y]:
			x += 1
print(x)


a = int(input())
x = []
y = []
t = 0
for i in range(0, a):
	s = input().split()
	x.append(int(s[0]))
	y.append(int(s[1]))
for i in x:
	t += y.count(i)
print(t)


def list_input():
	return list(map(int, input().split()))

def multiple_input():
	return map(int, input().split())
home = {}
away = {}
for _ in range(int(input())):
	(a, b) = multiple_input()
	if a in home:
		home[a] += 1
	else:
		home[a] = 1
	if b in away:
		away[b] += 1
	else:
		away[b] = 1
ans = 0
for i in home:
	if i in away:
		ans += home[i] * away[i]
print(ans)


n = input()
l = []
ans = 0
for i in range(int(n)):
	l.append(input().split())
nl = list(zip(*l))
for i in nl[0]:
	if i in nl[1]:
		ans += nl[1].count(i)
print(ans)


n = int(input())
l = []
for _ in range(n):
	(h, a) = map(int, input().split(' '))
	l.append((h, a))
answer = 0
for i in range(n * n):
	if l[i // n][0] == l[i % n][1]:
		answer += 1
print(answer)


n = int(input())
l1 = []
l2 = []
i = 0
while i < n:
	s = list(map(int, input().split()))
	l1.append(s[0])
	l2.append(s[1])
	i = i + 1
j = 0
a = 0
while j < n:
	b = l2.count(l1[j])
	a = a + b
	j = j + 1
print(a)


(home, guest) = ([], [])
for i in range(int(input())):
	(a, b) = map(int, input().split())
	home.append(a)
	guest.append(b)
count = 0
for i in home:
	count += guest.count(i)
print(count)


a = int(input())
mat = []
res = 0
for i in range(a):
	s = input().split()
	mat.append(s)
for i in range(a):
	for j in range(a):
		if i != j:
			if mat[i][0] == mat[j][1]:
				res += 1
print(res)


n = int(input())
colors = []
play = 0
for x in range(n):
	colors.append(list(map(int, input().split())))
for x in range(len(colors)):
	for y in range(len(colors)):
		if colors[x][0] == colors[y][1]:
			play += 1
print(play)


n = int(input())
home = []
guest = []
for _ in range(n):
	(a, b) = [int(x) for x in input().split()]
	home.append(a)
	guest.append(b)
count = 0
for i in range(len(home)):
	for j in range(len(home)):
		if home[i] == guest[j]:
			count += 1
print(count)


a = int(input())
inputs = []
n = 0
while n < a:
	y = input()
	n += 1
	inputs.append(y)
count = 0
for i in inputs:
	b = i.split()
	inputs1 = [k for k in inputs if k != i]
	for j in inputs1:
		c = j.split()
		if b[0] == c[1]:
			count += 1
print(count)


n = int(input())
s = []
t = []
m = 0
for i in range(n):
	(x, y) = map(int, input().split(' '))
	s.append(x)
	t.append(y)
p = len(s)
for i in range(p):
	for j in range(p):
		if s[i] == t[j]:
			m = m + 1
print(m)


l1 = []
l2 = []
x = []
c = 0
for i in range(int(input())):
	(a, b) = input().split()
	l1.append(a)
	l2.append(b)
for i in range(len(l1)):
	if l1[i] in l2:
		c = c + l2.count(l1[i])
print(c)


n = int(input())
h = {}
a = []
for i in range(0, n):
	inp = list(map(int, input().split()))
	if inp[0] in h.keys():
		h[inp[0]] = h[inp[0]] + 1
	else:
		h[inp[0]] = 1
	a.append(inp[1])
count = 0
for i in a:
	if i in h.keys():
		count = count + h[i]
print(count)


num = int(input())
home = []
away = []
for i in range(0, num):
	nums = input().split()
	home.append(nums[0])
	away.append(nums[1])
count = 0
for i in range(0, len(away)):
	for j in range(0, len(home)):
		if i != j and away[i] == home[j]:
			count += 1
print(count)


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


t = int(input())
x = []
y = []
while t:
	l = [int(i) for i in input().split()]
	x.append(l[0])
	y.append(l[1])
	t -= 1
c = 0
z = set(y)
for i in z:
	c += x.count(i) * y.count(i)
print(c)


n = int(input())
d = []
c = 0
for i in range(n):
	a = list(map(int, input().split()))
	d.append(a)
for i in range(n):
	for j in range(n):
		if (i > j or i < j) and d[i][0] == d[j][1]:
			c = c + 1
print(c)


n = int(input())
kiri = []
kanan = []
for i in range(n):
	z = list(map(int, input().split()))
	kiri.append(z[0])
	kanan.append(z[1])
count = 0
for i in range(n):
	for j in range(n):
		if kiri[i] == kanan[j]:
			count += 1
print(count)


import itertools
n = int(input())
games = n * (n - 1)
a = []
for _ in range(n):
	a.append(input().split(' '))
b = list(itertools.combinations(a, 2))
total = 0
for i in b:
	if i[0][0] == i[1][1]:
		total += 1
	if i[0][1] == i[1][0]:
		total += 1
print(total)


n = int(input())
L = list()
s = 0
for i in range(n):
	a = tuple(input().split())
	L.append(a)
for i in range(len(L)):
	for j in range(len(L)):
		if i != j and L[i][1] == L[j][0]:
			s += 1
print(s)


n = int(input())
l = []
ans = 0
for _ in range(n):
	l.append([int(i) for i in input().split(' ')])
for i in range(n):
	for j in range(n):
		if i != j:
			if l[i][0] == l[j][1]:
				ans += 1
print(ans)


n = int(input())
teams = []
for _ in range(n):
	teams.append(tuple(map(int, input().split())))
times = 0
for i in teams:
	for j in teams:
		if i[0] == j[1]:
			times += 1
print(times)


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


n = int(input())
home = []
away = []
for i in range(n):
	(h, a) = map(int, input().split())
	home.append(h)
	away.append(a)
score = 0
for i in range(n):
	jersey = away[i]
	for j in range(n):
		if jersey == home[j]:
			score += 1
print(score)


n = int(input())
H = []
A = []
for _ in range(n):
	(h, a) = map(int, input().split())
	H.append(h)
	A.append(a)
c = 0
for h in H:
	c += A.count(h)
print(c)


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


n = int(input())
L = []
c = 0
for i in range(n):
	L.append([int(x) for x in input().split()])
for x in L:
	for y in L:
		if x[1] == y[0]:
			c += 1
print(c)


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


n = int(input())
home = []
away = []
ans = 0
for i in range(n):
	(h, a) = list(map(int, input().split()))
	home.append(h)
	away.append(a)
for x in home:
	if x in away:
		ans += away.count(x)
print(ans)


n = int(input())
listx = []
for i in range(n):
	x = input().split()
	listx.append(x)
counter = 0
for i in listx:
	for x in listx:
		if i[0] == x[1]:
			counter += 1
print(counter)


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())
guest_colors = dict()
home_colors = dict()
for i in range(n):
	(c1, c2) = tuple(map(int, input().split()))
	if c1 in home_colors:
		home_colors[c1] += 1
	else:
		home_colors[c1] = 1
	if c2 in guest_colors:
		guest_colors[c2] += 1
	else:
		guest_colors[c2] = 1
count = 0
for c in home_colors:
	if c in guest_colors:
		count += home_colors[c] * guest_colors[c]
print(count)


n = int(input())
a = list()
b = list()
for i in range(n):
	x = input()
	x = x.split()
	a.append(int(x[0]))
	b.append(int(x[1]))
res = 0
for i in range(len(a)):
	for j in range(len(a)):
		if i != j and a[i] == b[j]:
			res += 1
print(res)


n = int(input())
temp_list = list()
for i in range(n):
	temp_list.append(str(input()).split())
value = 0
for i in range(n):
	for j in range(n):
		if temp_list[i][0] == temp_list[j][1]:
			value += 1
print(value)


n = int(input())
lis = []
for i in range(n):
	lis.append([int(x) for x in input().split()])
k = 0
for i in range(n):
	for j in range(n):
		if lis[i][1] == lis[j][0]:
			k += 1
print(k)


n = int(input())
k = []
for i in range(n):
	(x, y) = [int(j) for j in input().split()]
	k.append((x, y))
count = 0
for i in range(n):
	for j in range(n):
		if i != j and k[i][0] == k[j][1]:
			count += 1
print(count)


n = int(input())
w = []
i = []
c = 0
for x in range(n):
	d = list(input().split())
	w.append(d[0])
	i.append(d[1])
for y in w:
	c += i.count(y)
print(c)


n = int(input())
l = [[int(i) for i in input().split()[:2]] for j in range(n)]
s = set()
for i in range(n):
	s.add(l[i][0])
l1 = []
l2 = []
for i in range(n):
	for j in range(2):
		if j == 0:
			l1.append(l[i][j])
		else:
			l2.append(l[i][j])
c = 0
for i in s:
	a = l1.count(i)
	b = l2.count(i)
	c += a * b
print(c)


uu = int(input())
l1 = []
l2 = []
i = 0
m = 0
for x in range(uu):
	(a, b) = map(int, input().split())
	l1.append(a)
	l2.append(b)
for c in range(uu):
	te = l1[m]
	m += 1
	for x in l2:
		if te == x:
			i += 1
print(i)


import sys
input = sys.stdin.readline
n = int(input())
a = []
for i in range(n):
	z = list(map(int, input().split()))
	a.append(z)
ans = 0
for i in range(n):
	for j in range(n):
		if i != j and a[i][0] == a[j][1]:
			ans += 1
print(ans)


n = int(input())
m = n
s = 0
a = []
b = []
while n > 0:
	l = input().split()
	a.append(l[0])
	b.append(l[1])
	n = n - 1
for i in range(m):
	for k in range(m):
		if b[k] == a[i]:
			s = s + 1
print(s)


n = int(input())
(h, a) = ([], [])
for q in range(n):
	(hi, ai) = map(int, input().split())
	(h.append(hi), a.append(ai))
c = 0
for i in range(n):
	for j in range(n):
		if j != i:
			if a[j] == h[i]:
				c += 1
print(c)


n = int(input())
h = []
g = []
c = 0
for _ in range(n):
	(a, b) = map(int, input().split())
	h.append(a)
	g.append(b)
for e in h:
	c += g.count(e)
print(c)


t = int(input())
l = []
j = []
for i in range(t):
	(a, b) = map(int, input().split())
	l.append(a)
	j.append(b)
tot = 0
for u in range(t):
	h = j.count(l[u])
	if l[u] == j[u]:
		h = h - 1
	tot = tot + h
print(tot)


def solve(arr):
	counter = 0
	for i in range(len(arr)):
		for j in range(len(arr)):
			if i != j:
				if arr[i][1] == arr[j][0]:
					counter += 1
	print(counter)
h = input()
arr = list()
for i in range(int(h)):
	arr.append(input().split())
solve(arr)


arg = int(input())
h = []
a = []
for _ in range(0, arg):
	(i, j) = map(int, input().strip().split())
	h.append(i)
	a.append(j)
res = 0
for q in h:
	res += a.count(q)
print(res)


h = list()
g = list()
for _ in range(int(input())):
	s = input().split()
	h.append(s[0])
	g.append(s[1])
cnt = 0
for i in h:
	cnt += g.count(i)
print(cnt)


no_of_team = int(input())
list_of_team = []
for i in range(0, no_of_team):
	(h, g) = map(int, input().split())
	list_of_team.append([h, g])
flag = 0
count = 0
while flag <= no_of_team - 1:
	for i in range(0, no_of_team):
		if flag != i:
			if list_of_team[flag][0] == list_of_team[i][1]:
				count += 1
	flag += 1
print(count)


ans = []
for _ in range(int(input())):
	ans.append(list(map(int, input().split())))
result = 0
for i in range(len(ans)):
	for j in range(i + 1, len(ans)):
		if ans[i][0] == ans[j][1]:
			result += 1
		if ans[i][1] == ans[j][0]:
			result += 1
print(str(result), end='')


n = int(input())
l1 = []
l2 = []
count = 0
while n:
	(h, g) = map(int, input().split())
	l1.append(h)
	l2.append(g)
	n = n - 1
for i in l1:
	for j in l2:
		if i == j:
			count += 1
print(count)


n = int(input())
uni = [[]] * n
for i in range(n):
	uni[i] = list(map(int, input().split()))
count = 0
for i in range(n):
	for j in range(n):
		if i != j and uni[i][0] == uni[j][1]:
			count += 1
print(count)


from itertools import permutations
n = int(input())
a = [i for i in range(1, n + 1)]
h = []
g = []
for i in range(n):
	(hi, gi) = map(int, input().split())
	h.append(hi)
	g.append(gi)
new = list(permutations(a, 2))
c = 0
for i in new:
	if h[i[0] - 1] == g[i[1] - 1]:
		c += 1
print(c)


n = int(input())
ans = 0
lis = []
while n:
	l = list(map(int, input().split()))
	lis.append(l)
	n -= 1
cnt = 0
for i in range(len(lis)):
	for j in range(len(lis)):
		if i != j and lis[i][0] == lis[j][1]:
			cnt += 1
print(cnt)


num = int(input())
host = []
guest = []
for i in range(num):
	temp = input()
	temp = temp.split(' ')
	host.append(temp[0])
	guest.append(temp[1])
count = 0
for i in host:
	for j in guest:
		if i == j:
			count += 1
print(count)


T = int(input())
H = []
G = []
L = 0
for I in range(T):
	(A, B) = map(int, input().split())
	H.append(A)
	G.append(B)
for J in range(T):
	for K in range(T):
		if J != K:
			if H[J] == G[K]:
				L += 1
print(L)


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


def solve(color):
	count = 0
	for i in color:
		for j in color:
			if i == j:
				continue
			elif i[0] == j[1]:
				count += 1
	return count
n = int(input())
color = []
for i in range(n):
	(h, a) = map(int, input().split())
	color.append([h, a])
print(solve(color))


c = []
count = 0
for i in range(int(input())):
	(a, b) = map(int, input().split())
	c.append(a)
	c.append(b)
for k in range(0, len(c), 2):
	for j in range(1, len(c), 2):
		if c[k] == c[j]:
			count += 1
print(count)


data = []
for _ in range(int(input())):
	data.append([int(x) for x in input().split()])
ans = 0
for q in range(len(data)):
	for w in range(len(data)):
		if q == w:
			continue
		if data[q][1] == data[w][0]:
			ans += 1
print(ans)


Home = []
Guest = []
num_teams = int(input())
matches = 0
for _ in range(num_teams):
	(h, g) = [int(a) for a in input().strip().split()]
	Home.append(h)
	Guest.append(g)
for color in Home:
	for g_color in Guest:
		if color == g_color:
			matches += 1
print(matches)


(games, home, away) = ([], [], [])
res = 0
n = int(input())
for e in range(n):
	pair = [int(x) for x in input().split()]
	for e in pair:
		games.append(e)
for i in range(0, len(games), 2):
	home.append(games[i])
for i in range(1, len(games), 2):
	away.append(games[i])
for i in range(len(home)):
	for j in range(len(away)):
		if home[i] == away[j]:
			res += 1
print(res)


from collections import defaultdict
n = int(input())
(a, b, count) = (0, 0, 0)
a_dict = defaultdict(int)
b_dict = defaultdict(int)
for i in range(n):
	(a, b) = map(str, input().split())
	a_dict[a] += 1
	b_dict[b] += 1
a = a_dict.keys()
b = b_dict.keys()
for i in a:
	if i in b:
		count += a_dict[i] * b_dict[i]
print(count)


import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, random, time, copy, functools
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20
eps = 1.0 / 10 ** 10
mod = 10 ** 9 + 7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]

def LI():
	return [int(x) for x in sys.stdin.readline().split()]

def LI_():
	return [int(x) - 1 for x in sys.stdin.readline().split()]

def LF():
	return [float(x) for x in sys.stdin.readline().split()]

def LS():
	return sys.stdin.readline().split()

def I():
	return int(sys.stdin.readline())

def F():
	return float(sys.stdin.readline())

def S():
	return input()

def pf(s):
	return print(s, flush=True)

def main():
	n = I()
	h = collections.defaultdict(int)
	o = collections.defaultdict(int)
	for _ in range(n):
		(a, b) = LI()
		h[a] += 1
		o[b] += 1
	r = 0
	for (k, v) in h.items():
		r += v * o[k]
	return r
print(main())


c = []
d = []
n = int(input())
games = 0
for i in range(n):
	(a, b) = map(int, input().split())
	c.append(a)
	d.append(b)
for i in c:
	if i in d:
		games += d.count(i)
print(games)


x = int(input())
o = 0
l = []
for i in range(x):
	t = list(map(int, input().split()))
	l.append(t)
for i in l:
	for j in l:
		if i != j:
			if i[0] == j[1]:
				o += 1
print(o)


n = int(input())
s = []
count = 0
for _ in range(n):
	s.append(list(map(int, input().split())))
for i in range(n):
	t = s[i][0]
	for j in range(n):
		p = s[j][1]
		if t == p:
			count += 1
print(count)


n = int(input())
list1 = []
list2 = []
count = 0
for i in range(n):
	(first, second) = map(int, input().split())
	list1.append(first)
	list2.append(second)
for i in list1:
	a = list2.count(i)
	count = count + a
print(count)


teams = int(input())
matches = teams * (teams - 1)
c = []
d = []
for a in range(teams):
	(a, b) = map(int, input().split())
	c.append(a)
	d.append(b)
count = 0
for i in range(len(c)):
	for j in range(len(d)):
		if i != j and c[i] == d[j]:
			count += 1
print(count)


n = int(input())
h = []
a = []
count = 0
for _ in range(n):
	inp = input().split()
	h.append(int(inp[0]))
	a.append(int(inp[1]))
for i in range(n):
	for j in range(n):
		if i == j:
			continue
		elif h[i] == a[j]:
			count += 1
print(count)


n = int(input())
d = []
for i in range(0, n):
	a = input()
	a = a.split()
	d += [int(i) for i in a]
locales = [d[i] for i in range(0, 2 * n) if i % 2 == 0]
visitantes = [d[i] for i in range(1, 2 * n) if i % 2 != 0]
p = 0
for i in locales:
	for j in visitantes:
		if i == j:
			p += 1
print(p)


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


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


n = int(input())
l = list()
l1 = list()
l2 = list()
l3 = list()
i = 0
while i < n:
	i = i + 1
	s = input()
	l = s.split()
	l1.append(l)
for i in l1:
	l2.append(i[0])
	l3.append(i[1])
count = 0
for k in l2:
	for l in l3:
		if k == l:
			count = count + 1
print(count)


from collections import Counter
N = int(input())
c_home = Counter()
c_away = Counter()
for n in range(N):
	(hi, ai) = list(map(int, input().split()))
	c_home.update([hi])
	c_away.update([ai])
res = 0
for i in c_home.elements():
	res += c_away[i]
print(res)


a = int(input())
lista = []
listb = []
jumlah = 0
for z in range(a):
	(a, b) = map(int, input().split())
	lista.append(a)
	listb.append(b)
for zz in range(len(lista) - 1):
	for zza in range(zz + 1, len(listb)):
		if lista[zz] == listb[zza]:
			jumlah = jumlah + 1
for zzz in range(len(listb) - 1):
	for zzzb in range(zzz + 1, len(listb)):
		if listb[zzz] == lista[zzzb]:
			jumlah = jumlah + 1
print(jumlah)


n = int(input())
lst1 = []
lst2 = []
counter = 0
for i in range(n):
	x = input().split()
	lst1.append(x[0])
	lst2.append(x[1])
for i in range(len(lst1)):
	for j in range(len(lst2)):
		counter += lst1[i] == lst2[j]
print(counter)


import sys
import math

def games():
	datain = []
	shirts = 0
	homeshirts = []
	awayshirts = []
	teams = int(input())
	for i in range(teams):
		datain.append(input().split())
	for i in range(teams):
		homeshirts.append(datain[i][0])
	for i in range(teams):
		awayshirts.append(datain[i][1])
	for i in homeshirts:
		shirts += awayshirts.count(i)
	print(shirts)
games()


a = [input().split() for _ in range(int(input()))]
print(sum((x[0] == y[1] for x in a for y in a)))


n = int(input())
i = 0
home = []
guest = []
i = 0
k = 0
for i in range(n):
	(x, y) = map(int, input().split())
	home.append(x)
	guest.append(y)
cnt = 0
for i in range(n):
	for k in range(n):
		if home[i] == guest[k]:
			cnt = cnt + 1
print(cnt)


hguniforms = ''
a = int(input())
teams = []
for i in range(a):
	tmp = []
	hguniforms = input().split()
	tmp.append(int(hguniforms[0]))
	tmp.append(int(hguniforms[1]))
	teams.append(tmp)
fcount = 0
for i in range(a):
	for j in range(i + 1, a):
		if teams[i][0] == teams[j][1]:
			fcount += 1
		if teams[i][1] == teams[j][0]:
			fcount += 1
print(fcount)


n = int(input())
b = []
for x in range(n):
	b += list(map(int, input().split()))
c = []
d = []
i = 0
while i < n * 2:
	c.append(b[i])
	i += 2
i = 1
while i < n * 2:
	d.append(b[i])
	i += 2
count = 0
for x in c:
	for y in d:
		if x == y:
			count += 1
print(count)


n = int(input())
li = list()
i = 0
while i < n:
	li.append(list(map(int, input().split(' '))))
	i = i + 1
count = 0
i = 0
while i < n:
	j = 0
	while j < n:
		if li[i][0] == li[j][1] and i != j:
			count = count + 1
		j = j + 1
	i = i + 1
print(count)


num = int(input())
n1 = []
n2 = []
while num > 0:
	num1 = input().split()
	n1.append(num1[0])
	n2.append(num1[1])
	num -= 1
n3 = 0
for i in n1:
	for j in n2:
		if i == j:
			n3 += 1
print(n3)


n = int(input())
b = 0
i = 0
list1 = []
list2 = []
while i < n:
	(h, a) = map(int, input().split())
	list1.append(h)
	list2.append(a)
	for k in list1:
		if k == a:
			b = b + 1
		else:
			continue
	for j in list2:
		if j == h:
			b = b + 1
		else:
			continue
	i = i + 1
print(b)


g = int(input())
hc = []
gc = []
while g:
	game = input().split()
	hc.append(int(game[0]))
	gc.append(int(game[1]))
	g -= 1
c = 0
for i in hc:
	for j in gc:
		if i == j:
			c += 1
print(c)


n = int(input())
M = [list(map(int, input().split())) for i in range(n)]
s = 0
for i in range(n):
	h = M[i][0]
	for j in range(n):
		if j != i and h == M[j][1]:
			s += 1
print(s)


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


gamesNum = int(input())
inputList = list()
gamesList = list()
for game in range(gamesNum):
	inputList = list(map(int, input().split()))
	gamesList.append(inputList)
counter = 0
for j in range(gamesNum - 1):
	for k in range(j + 1, gamesNum):
		if gamesList[j][0] == gamesList[k][1]:
			counter += 1
		if gamesList[j][1] == gamesList[k][0]:
			counter += 1
print(counter)


import sys
import math
t = int(input())
a = []
for i in range(t):
	b = list(map(int, input().split()))
	a.append(b)
cnt = 0
for i in range(0, t):
	for j in range(0, t):
		if i != j and a[i][0] == a[j][1]:
			cnt += 1
print(cnt)


n = int(input())
count = 0
h_list = []
a_list = []
while n > 0:
	(h, a) = map(int, input().split())
	h_list.append(h)
	a_list.append(a)
	n -= 1
for i in h_list:
	count += a_list.count(i)
print(count)


from collections import Counter

def color():
	n1 = int(input())
	me = Counter()
	ay = Counter()
	for i in range(n1):
		(h1, a1) = map(int, input().strip().split())
		me[h1] += 1
		ay[a1] += 1
	s = 0
	for key in me.keys():
		t1 = me[key] * ay[key]
		s += t1
	return s
print(color())


def _268A(home_colours, away_colours):
	count = 0
	for index in range(len(home_colours)):
		count += away_colours.count(home_colours[index])
	return count
number_of_teams = int(input())
home_colours = []
away_colours = []
for index in range(number_of_teams):
	team = list(map(lambda x: int(x), input().split()))
	home_colours.append(team[0])
	away_colours.append(team[1])
print(_268A(home_colours, away_colours))


n = int(input())
(homeUni, guestUni, gamesBothGuest) = ([None] * n, [None] * n, 0)
for i in range(0, n):
	(homeUni[i], guestUni[i]) = [int(u) for u in input().split()]
for i in range(0, n):
	gamesBothGuest = gamesBothGuest + guestUni.count(homeUni[i])
print(gamesBothGuest)


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


n = int(input())
c = 0
h = []
g = []
for i in range(0, n):
	l = [int(x) for x in input().split()]
	h.append(l[0])
	g.append(l[1])
for i in range(1, 101):
	a = 0
	b = 0
	for j in h:
		if j == i:
			a = a + 1
	for j in g:
		if j == i:
			b = b + 1
	c = c + a * b
print(c)


teams = int(input())
count = 0
home_list = []
away_list = []
for team in range(teams):
	(h, a) = map(str, input().split())
	home_list.append(h)
	away_list.append(a)
for color in home_list:
	count += away_list.count(color)
print(count)


a = list()
b = list()
c = 0
for i in range(int(input())):
	(z, x) = map(int, input().split())
	a.append(z)
	b.append(x)
for i in a:
	c += b.count(i)
print(c)


def lf(n):
	c = 0
	while n > 0:
		if n % 10 == 4 or n % 10 == 7:
			c += 1
		n = n // 10
	return c

def ii():
	return int(input())

def mi():
	return map(int, input().split())

def li():
	return list(mi())
n = ii()
a = []
b = []
count = 0
for i in range(n):
	(p, q) = mi()
	a.append(p)
	b.append(q)
for i in range(n):
	for j in range(n):
		if i == j:
			continue
		elif a[i] == b[j]:
			count += 1
print(count)


n = int(input())
t = [[0, 0] for k in range(n)]
count = 0
for i in range(n):
	t[i] = [int(o) for o in input().split(' ')]
for i in range(n):
	for j in range(n):
		if i != j and t[i][0] == t[j][1]:
			count += 1
print(count)


def main():
	N = int(input())
	home = []
	guest = []
	for _ in range(N):
		(h, g) = map(int, input().split())
		home.append(h)
		guest.append(g)
	cnt = 0
	for i in range(len(home)):
		for j in range(len(guest)):
			if home[i] == guest[j]:
				cnt += 1
	print(cnt)
main()


n = int(input())
A = []
for i in range(n):
	a = input()
	l = a.split()
	A.append(l)
count = 0
for i in range(n):
	for j in range(i + 1, n):
		if A[i][0] == A[j][1]:
			count += 1
		if A[i][1] == A[j][0]:
			count += 1
print(count)


import math
n = int(input())
data = [[0 for j in range(2)] for i in range(n)]
for i in range(n):
	(data[i][0], data[i][1]) = map(int, input().split())
count = 0
for i in range(n):
	for j in range(n):
		if i == j:
			continue
		if data[i][0] == data[j][1]:
			count += 1
print(count)


no_of_teams = int(input())
teams = []
cases = 0
for team in range(no_of_teams):
	(home, away) = map(str, input().split())
	team = (home, away)
	teams.append(team)
for Home in teams:
	for Away in teams:
		if Home == Away:
			continue
		if Home[0] == Away[1]:
			cases += 1
print(cases)


n = int(input())
a = []
b = []
for i in range(n):
	line = input().split()
	a.append(line[0])
	b.append(line[1])
num = 0
for i in range(n):
	if a[i] in b:
		num += b.count(a[i])
print(num)


n = int(input())
(home, guest, answer) = ([], [], 0)
for i in range(n):
	temp = input().split()
	home.append(int(temp[0]))
	guest.append(int(temp[1]))
for i in range(len(home)):
	for j in range(len(guest)):
		if i != j and home[i] == guest[j]:
			answer += 1
print(answer)


n = int(input())
x = []
c = 0
for i in range(n):
	s = list(input().split())
	x.append([s[j] for j in range(2)])
for i in range(n):
	for j in range(n):
		if x[i][0] == x[j][1]:
			c += 1
print(c)


n = int(input())
uni = []
for i in range(n):
	uni.append([int(x) for x in input().split()])
home = [x[0] for x in uni]
guest = [x[1] for x in uni]
count = 0
for i in home:
	count += guest.count(i)
print(count)


import itertools
n = int(input())
games = []
change = 0
for i in range(0, n):
	aux = input()
	aux = [int(n) for n in aux.split()]
	games.append(aux)
games = list(itertools.permutations(games, 2))
for j in games:
	if j[0][0] == j[1][1]:
		change = change + 1
print(str(change))


N = int(input())
(homecolors, guestcolors) = ([], [])
swaps = 0
for i in range(N):
	(homecolor, guestcolor) = [int(x) for x in input().split()]
	homecolors.append(homecolor)
	guestcolors.append(guestcolor)
for i in homecolors:
	swaps += guestcolors.count(i)
print(swaps)


n = int(input())
hl = []
gl = []
for i in range(n):
	(h, g) = map(int, input().split())
	hl.append(h)
	gl.append(g)
c = 0
for x in range(n):
	for y in range(n):
		if hl[x] == gl[y]:
			c += 1
print(c)


from copy import deepcopy
n = int(input())
home = []
guest = []
for x in range(n):
	(a, b) = map(int, input().split())
	home.append(a)
	guest.append(b)
count = 0
for x in range(n):
	list1 = deepcopy(guest)
	list1.pop(x)
	for y in range(n - 1):
		if home[x] == list1[y]:
			count += 1
print(count)


t = int(input())
a = []
for _ in range(t):
	(x, y) = map(int, input().split())
	a.append([x, y])
c = 0
for h in range(len(a)):
	for g in range(len(a)):
		if g == h:
			continue
		if a[h][0] == a[g][1]:
			c += 1
print(c)


A = []
B = []
c = 0
for _ in range(int(input())):
	(a, b) = map(list, input().split())
	A.append(a)
	B.append(b)
for i in B:
	for j in A:
		if i == j:
			c += 1
print(c)


n = int(input())
l = []
for i in range(n):
	temp = list(map(int, input().split()))[:2]
	l.append(temp)
c = 0
for i in range(n):
	for j in range(n):
		if i == j:
			continue
		if l[i][0] == l[j][1]:
			c += 1
print(c)


def main():
	n = int(input())
	homes = [0] * n
	aways = [0] * n
	for i in range(n):
		(h, a) = [int(_) for _ in input().split()]
		homes[i] = h
		aways[i] = a
	count = 0
	for i in range(n - 1):
		for j in range(i + 1, n):
			if homes[i] == aways[j]:
				count += 1
			if homes[j] == aways[i]:
				count += 1
	print(count)
main()


number = int(input())
hostColor = []
guestColor = []
for i in range(number):
	str1 = input()
	List = str1.split(' ')
	hostColor.append(int(List[0]))
	guestColor.append(int(List[1]))
sameColor = 0
for color in hostColor:
	for newColor in guestColor:
		if color == newColor:
			sameColor += 1
print(sameColor)


teams = int(input())
teams = [input().split() for i in range(teams)]
count = 0
for uniforms in teams:
	other_teams = [stuff for stuff in teams]
	other_teams.remove(uniforms)
	for forms in other_teams:
		if forms[1] == uniforms[0]:
			count = count + 1
print(count)


t = int(input())
homeColor = []
guestColor = []
for _ in range(t):
	(home, guest) = input().split()
	homeColor.append(home)
	guestColor.append(guest)
ans = 0
for i in range(t):
	ans += guestColor.count(homeColor[i])
print(ans)


n = int(input())
l = []
ans = 0
for i in range(n):
	x = list(map(int, input().split()))
	l.append(x[0])
	l.append(x[1])
(l1, l2) = (l[0::2], l[1::2])
for i in l2:
	ans += l1.count(i)
print(ans)


n = int(input())
cnt = 0
hl = []
gl = []
for i in range(n):
	(h, g) = map(int, input().split())
	hl.append(h)
	gl.append(g)
for i in hl:
	for j in gl:
		if i == j:
			cnt += 1
print(cnt)


a = int(input())
h = []
a1 = []
b = 0
for i in range(a):
	(h1, a2) = map(int, input().split())
	h.append(h1)
	a1.append(a2)
for i in range(a):
	for j in range(a):
		if i != j and h[i] == a1[j]:
			b += 1
print(b)


import sys
it = iter(sys.stdin.read().splitlines())
n = int(next(it))
teams = []
for i in range(n):
	teams.append([int(x) for x in next(it).split()])
times = 0
for x in range(len(teams)):
	for y in range(0, len(teams)):
		if x != y:
			if teams[x][0] == teams[y][1]:
				times += 1
print(times)


n = int(input())
teams = []
for _ in range(n):
	teams.append([int(x) for x in input().split(' ')])
result = 0
for i in range(n):
	host = teams[i][0]
	for j in range(n):
		if i != j:
			guest = teams[j][1]
			if host == guest:
				result += 1
print(result)


n = int(input())
tab = []
while n:
	(x, y) = map(int, input().split())
	tab.append([x, y])
	n -= 1
res = 0
for (x1, y1) in enumerate(tab):
	for (x2, y2) in enumerate(tab):
		if x2 != x1 and y2[1] == y1[0]:
			res += 1
print(res)


n = int(input())
first = []
second = []
count = 0
for i in range(n):
	(h, a) = map(int, input().split())
	first.append(h)
	second.append(a)
for i in range(len(first)):
	for j in range(len(second)):
		if first[i] == second[j]:
			count += 1
print(count)


n = int(input())
(A, H) = ([0] * n, [0] * n)
for i in range(n):
	(A[i], H[i]) = map(int, input().split())
print(sum((H.count(a) for a in A)))


n = int(input())
list1 = []
list2 = []
count = 0
for i in range(n):
	s = list(map(int, input().split()))
	list1.append(s[0])
	list2.append(s[1])
for i in list1:
	if i in list2:
		count += list2.count(i)
print(count)


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


home = []
guest = []
a = int(input())
for i in range(0, a):
	b = list(map(int, input().split(' ')))
	home.append(b[0])
	guest.append(b[1])
num = 0
for i in range(0, a):
	for j in range(0, a):
		if home[i] == guest[j]:
			num += 1
print(num)


teams = int(input())
teamcolorsguest = []
teamcolorshost = []
changes = 0
for x in range(teams):
	(a, b) = map(int, input().split())
	teamcolorshost.append(a)
	teamcolorsguest.append(b)
count = 0
for x in range(teams):
	for y in range(teams):
		if teamcolorshost[x] == teamcolorsguest[y]:
			count += 1
print(count)


a = int(input())
s = [[int(x) for x in input().split()] for x in range(a)]
c = 0
for i in range(a):
	for x in range(a):
		if i == x:
			continue
		if s[i][0] == s[x][1]:
			c += 1
print(c)


h = []
a = []
x = 0
jersey = 0
j = int(input())
for g in range(j):
	(x, y) = input().split()
	h.append(x)
	a.append(y)
for m in range(j):
	x = a.count(h[m])
	jersey += x
print(jersey)


n = int(input())
teams = {}
guest = 0
for i in range(n):
	teams[i + 1] = list(map(int, input().split()))
for i in range(1, n + 1):
	for j in range(1, n + 1):
		if i != j:
			if teams[i][0] == teams[j][1]:
				guest += 1
print(guest)


def main():
	n = int(input())
	(L1, L2) = ([], [])
	c = 0
	for i in range(n):
		(a, b) = input().split()
		L1.append(a)
		L2.append(b)
	for i in range(n):
		c += L2.count(L1[i])
	print(c)
main()


s = int(input())
m = []
l = []
count = 0
for i in range(0, s):
	a = input().split()
	b = int(a[0])
	m.append(b)
	c = int(a[1])
	l.append(c)
for j in m:
	r = l.count(j)
	count = count + r
print(count)


n = int(input())
i = 0
lst = list()
home = list()
away = list()
while i < n:
	data = input()
	for j in data.split():
		lst.append(int(j))
	i = i + 1
l = len(lst)
k = 0
while k < l - 1:
	home.append(lst[k])
	k = k + 2
j = 0
while j < l:
	away.append(lst[j + 1])
	j = j + 2
count = 0
for a in home:
	for b in away:
		if a == b:
			count = count + 1
print(count)


n = int(input())
home = []
guest = []
while n:
	(h, g) = list(map(int, input().split()))
	home.append(h)
	guest.append(g)
	n = n - 1
count = 0
for i in range(len(home)):
	for j in range(len(guest)):
		if home[i] == guest[j]:
			count = count + 1
print(count)


n = int(input())
host_uni = []
guest_uni = []
for i in range(0, n):
	(x, y) = input().split()
	host_uni.append(int(x))
	guest_uni.append(int(y))
res = 0
for i in range(0, n):
	res += guest_uni.count(host_uni[i])
print(res)


def finder(L):
	number = 0
	for i in range(0, len(L)):
		for j in range(0, len(L)):
			if i == j:
				pass
			elif L[i][0] == L[j][1]:
				number += 1
	return number
n = int(input())
L = []
for i in range(0, n):
	temp = list(map(int, input().split()))
	L.append(temp)
print(finder(L))


isDebug = False
n = int(input())
t = []
for i in range(0, n):
	t.append(input())
c = 0
for i in range(0, n):
	(hi, gi) = str(t[i]).split()
	if isDebug:
		print(f'hi={hi}, gi={gi}')
	for j in range(0, n):
		if i == j:
			continue
		(hj, gj) = str(t[j]).split()
		if isDebug:
			print(f'hj={hj}, gj={gj}')
		c = c + (1 if hi == gj else 0)
	if isDebug:
		print(f'c={c}')
		print(f'-----')
print(f'{c}')


class Uniform:

	def __init__(self, home, guest):
		self.home = home
		self.guest = guest
n = int(input())
seq = []
for _ in range(n):
	(home, guest) = map(int, input().split())
	seq += [Uniform(home, guest)]
ans = 0
for a in seq:
	for b in seq:
		if a.home == b.guest:
			ans += 1
print(ans)


n = int(input())
A = []
B = []
for i in range(n):
	ab = input().split()
	a = int(ab[0])
	b = int(ab[1])
	A.append(a)
	B.append(b)
s = 0
for d in range(n):
	for c in range(n):
		if A[d] == B[c]:
			s = s + 1
print(s)


n = int(input())
a = list()
for i in range(n):
	a.append([int(x) for x in input().split()])
c = 0
for elt1 in a:
	for elt2 in a:
		if elt1 != elt2 and elt1[0] == elt2[1]:
			c += 1
print(c)


n = int(input())
teams = []
for _ in range(n):
	teams.append(input())
times = 0
for i in range(n):
	hometeam = teams[i].split()
	for x in range(n):
		if x != i:
			if hometeam[0] == teams[x].split()[1]:
				times += 1
print(times)


num_teams = int(input())
home_colors = list()
guest_colors = list()
num_swaps = 0
for _ in range(num_teams):
	(home_color, guest_color) = map(int, input().split())
	(home_colors.append(home_color), guest_colors.append(guest_color))
for home_index in range(num_teams):
	for guest_index in range(num_teams):
		if home_colors[home_index] == guest_colors[guest_index]:
			num_swaps += 1
print(num_swaps)


count_commands = int(input())
homes = []
guests = []
count = 0
for i in range(count_commands):
	color_command = list(map(int, input().split()))
	homes.append(color_command[0])
	guests.append(color_command[1])
for i in range(len(homes)):
	for j in range(len(guests)):
		if i != j and homes[i] == guests[j]:
			count += 1
print(count)


n = int(input())
uniform = []
t = 0
while t < n:
	uniform = uniform + input().split()
	t = t + 1
home = []
guest = []
for i in range(2 * n):
	if i % 2 == 1:
		home.append(uniform[i])
	else:
		guest.append(uniform[i])
num = 0
for i in home:
	if i in guest:
		num = num + guest.count(i)
print(num)


t = int(input())
values = []
for i in range(t):
	values.append(tuple(map(int, input().split(' '))))
i = 0
count = 0
while i < t:
	for j in range(len(values)):
		if j == i:
			continue
		if values[i][0] == values[j][1]:
			count += 1
	i += 1
print(count)


lst = []
s = []
c = 0
n = int(input())
for i in range(n):
	lst = [int(x) for x in input().split()]
	s.append(lst)
for i in range(len(s)):
	for j in range(len(s)):
		if i == j:
			continue
		h = s[i][0]
		a = s[j][1]
		if h == a:
			c = c + 1
print(c)


from __future__ import division, print_function
import sys
from sys import stdin, stdout
import bisect
from bisect import bisect_left as bl
from bisect import bisect_right as br
import itertools
from collections import Counter
import collections
import math
import heapq
import re

def modinv(n, p):
	return pow(n, p - 2, p)

def cin():
	return map(int, sin().split())

def ain():
	return list(map(int, sin().split()))

def sin():
	return input()

def inin():
	return int(input())

def Divisors(n):
	l = []
	for i in range(1, int(math.sqrt(n) + 1)):
		if n % i == 0:
			if n // i == i:
				l.append(i)
			else:
				l.append(i)
				l.append(n // i)
	return l

def most_frequent(list):
	return max(set(list), key=list.count)

def GCD(x, y):
	while y:
		(x, y) = (y, x % y)
	return x

def ncr(n, r, p):
	t = fact[n] * (ifact[r] * ifact[n - r] % p) % p
	return t

def Convert(string):
	li = list(string.split(''))
	return li

def SieveOfEratosthenes(n):
	global prime
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	f = []
	for p in range(2, n):
		if prime[p]:
			f.append(p)
	return f
prime = []
q = []

def dfs(n, d, v, c):
	global q
	v[n] = 1
	x = d[n]
	q.append(n)
	j = c
	for i in x:
		if i not in v:
			f = dfs(i, d, v, c + 1)
			j = max(j, f)
	return j

def main():
	n = inin()
	arr = []
	count = 0
	for i in range(n):
		arr.append(ain())
	for j in range(n):
		for k in range(j + 1, n):
			if arr[j][0] == arr[k][1]:
				count += 1
			if arr[j][1] == arr[k][0]:
				count += 1
	print(count)
py2 = round(0.5)
if py2:
	from future_builtins import ascii, filter, hex, map, oct, zip
	range = xrange
import os, sys
from io import IOBase, BytesIO
BUFSIZE = 8192

class FastIO(BytesIO):
	newlines = 0

	def __init__(self, file):
		self._file = file
		self._fd = file.fileno()
		self.writable = 'x' in file.mode or 'w' in file.mode
		self.write = super(FastIO, self).write if self.writable else None

	def _fill(self):
		s = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
		self.seek((self.tell(), self.seek(0, 2), super(FastIO, self).write(s))[0])
		return s

	def read(self):
		while self._fill():
			pass
		return super(FastIO, self).read()

	def readline(self):
		while self.newlines == 0:
			s = self._fill()
			self.newlines = s.count(b'\n') + (not s)
		self.newlines -= 1
		return super(FastIO, self).readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.getvalue())
			(self.truncate(0), self.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		if py2:
			self.write = self.buffer.write
			self.read = self.buffer.read
			self.readline = self.buffer.readline
		else:
			self.write = lambda s: self.buffer.write(s.encode('ascii'))
			self.read = lambda : self.buffer.read().decode('ascii')
			self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


n = int(input())
color_L = []
count = 0
for i in range(n):
	color_L.append(tuple(map(int, input().split())))
for k in range(n):
	for i in range(n):
		if i == k:
			continue
		elif color_L[k][0] == color_L[i][1]:
			count += 1
print(count)


n = int(input())
a = [[0 for col in range(2)] for row in range(n)]
for i in range(n):
	a[i] = [int(i) for i in input().split()]
s = 0
for i in range(n):
	for j in range(i + 1, n):
		s = s + (a[i][0] == a[j][1]) + (a[i][1] == a[j][0])
print(s)


n = int(input())
host = [0] * n
guest = [0] * n
for i in range(n):
	(host[i], guest[i]) = input().split()
	(host[i], guest[i]) = (int(host[i]), int(guest[i]))
ans = 0
for i in range(n):
	for j in range(n):
		if i != j and host[i] == guest[j]:
			ans += 1
print(ans)


t = int(input())
l = []
ans = 0
for _ in range(t):
	(a, b) = map(int, input().split())
	l.append([a, b])
for i in range(t):
	for j in range(t):
		if l[i][1] == l[j][0]:
			ans += 1
print(ans)


h = []
g = []
t = 0
for _ in ' ' * int(input()):
	(a, b) = input().split()
	h.append(a)
	g.append(b)
for hh in h:
	t += g.count(hh)
print(t)


n = int(input().strip())
nm = 0
(h, a) = ([], [])
for i in range(n):
	(x, y) = input().split(' ')
	h.append(x)
	a.append(y)
	for j in range(i):
		if h[i] == a[j]:
			nm += 1
		if a[i] == h[j]:
			nm += 1
print(nm)


test = int(input())
hi = []
gi = []
c = 0
for _ in range(test):
	(h, g) = map(int, input().split())
	hi.append(h)
	gi.append(g)
for i in gi:
	for j in hi:
		if j == i:
			c += 1
print(c)


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


n = int(input())
c = 0
l1 = []
l2 = []
for _ in range(n):
	(h, g) = map(int, input().split())
	l1.append(h)
	l2.append(g)
for i in range(n):
	for j in range(n):
		if l1[i] == l2[j]:
			c += 1
print(c)


n = int(input())
count = 0
matrix = [[2 for x in range(2)] for y in range(n)]
for i in range(n):
	(matrix[i][0], matrix[i][1]) = map(int, input().split())
for i in range(n):
	for j in range(n):
		if matrix[i][0] == matrix[j][1]:
			count += 1
print(count)


n = int(input())
(home, guest) = (list(), list())
(h, g) = map(int, input().split())
home.append(h)
guest.append(g)
cont = 0
for i in range(n - 1):
	(h, g) = map(int, input().split())
	for gue in guest:
		if h == gue:
			cont += 1
	for hom in home:
		if g == hom:
			cont += 1
	home.append(h)
	guest.append(g)
print(cont)


from collections import Counter
n = int(input())
lst = []
for i in range(n):
	lst += list(map(int, input().split()))
lst1 = lst[0:-1:2]
lst2 = lst[1:-1:2]
lst2.append(lst[-1])
lst1 = Counter(lst1)
lst2 = Counter(lst2)
counter = 0
for i in lst1:
	counter += lst1[i] * lst2[i]
	i += 1
print(counter)


n = int(input())
ar = []
for i in range(n):
	(x, y) = map(int, input().split())
	ar.append((x, y))
c = 0
for (i1, j1) in ar:
	for (i2, j2) in ar:
		if i1 != i2 and i1 == j2:
			c += 1
print(c)


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


number_of_teams = int(input())
home = list()
guest = list()
i = 0
while i < number_of_teams:
	x = list(map(int, input().split()))
	home.append(x[0])
	guest.append(x[1])
	i += 1
matches = 0
for color_home in home:
	for color_guest in guest:
		if color_home == color_guest:
			matches += 1
print(matches)


n = int(input())
A = []
B = []
for i in range(n):
	s = input()
	AB = [int(x) for x in s.split(' ')]
	A.append(AB[0])
	B.append(AB[1])
s = 0
for i in range(n):
	for j in range(n):
		s += A[i] == B[j] and i != j
print(s)


a = int(input())
t = []
for i in range(a):
	r = list(map(int, input().split(' ')))
	t.append(r)
c = 0
for i in range(len(t) - 1):
	for j in range(i + 1, len(t)):
		if t[i][0] == t[j][1]:
			c += 1
		if t[i][1] == t[j][0]:
			c += 1
print(c)


import sys
n = int(input())
a = []
h = []
c = 0
for i in range(n):
	nums = list(map(int, input().split()))
	a.append(nums[0])
	h.append(nums[1])
for i in range(n):
	for j in range(n):
		if i != j and a[i] == h[j]:
			c += 1
print(c)


n = int(input())
r = []
cnt = 0
for i in range(n):
	r.extend([list(map(int, input().split()))])
for i in range(n):
	for j in range(n):
		if r[i][0] == r[j][1]:
			cnt += 1
print(cnt)


n = int(input(''))
i = 0
lis_1 = list()
lis_2 = list()
while i < n:
	(a, b) = map(int, input('').split())
	lis_1.append(a)
	lis_2.append(b)
	i += 1
s = 0
for i in lis_1:
	for j in lis_2:
		if i == j:
			s += 1
		else:
			s = s
print(s)


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


n = int(input())
ar = []
for x in range(n):
	ar.append(list(map(int, input().split())))
s = 0
for x in range(n):
	for y in range(x + 1, n):
		if ar[x][0] == ar[y][1]:
			s += 1
		if ar[x][1] == ar[y][0]:
			s += 1
print(s)


def solution(teams, n):
	result = 0
	for i in range(n):
		host_color = teams[i][0]
		for j in range(n):
			if i == j:
				continue
			guest_color = teams[j][1]
			if host_color == guest_color:
				result += 1
	return result
n = int(input())
teams = []
for _ in range(n):
	inp = list(map(int, input().split()))
	teams.append(inp)
print(solution(teams, n))


cnt = 0
hu = []
ha = []
for i in range(int(input())):
	(h, a) = map(int, input().split(' '))
	hu.append(h)
	ha.append(a)
for a in ha:
	cnt += hu.count(a)
print(cnt)


n = int(input())
(a, b) = zip(*(input().split() for _ in range(n)))
print(sum((a.count(j) for j in b)))


from sys import stdin
n = int(stdin.readline())
h = []
g = []
res = 0
for i in range(n):
	(a, b) = map(int, stdin.readline().split())
	h.append(a)
	g.append(b)
for x in h:
	for y in g:
		if x == y:
			res += 1
print(res)


test = int(input())
h = []
g = []
for t in range(test):
	(he, ge) = list(map(int, input().split()))
	h.append(he)
	g.append(ge)
count = 0
for i in range(len(h)):
	for j in range(len(g)):
		if g[j] == h[i]:
			count += 1
print(count)


N = int(input())
home = []
guest = []
for z in range(N):
	(h, g) = map(int, input().split())
	home.append(h)
	guest.append(g)
count = 0
for i in range(N):
	for j in range(N):
		if i != j:
			if home[i] == guest[j]:
				count += 1
print(count)


color = [input().split() for _ in range(int(input()))]
print(sum(([c[1] for c in color].count(a) for a in [c[0] for c in color])))


n = int(input())
cList = []
for i in range(n):
	color = [int(x) for x in input().split()]
	cList.append(color)
cnt = 0
for i in range(1, n):
	for j in range(i):
		if cList[i][1] == cList[j][0]:
			cnt += 1
		if cList[i][0] == cList[j][1]:
			cnt += 1
print(cnt)


n = int(input())
l = []
c = 0
for _ in range(n):
	l1 = [int(x) for x in input().split()]
	l.append(l1)
for i in range(n):
	t = l[i][0]
	for j in l:
		if j[1] == t:
			c += 1
print(c)


n = int(input())
w = 0
list1 = []
list2 = []
for i in range(n):
	(a, b) = map(lambda x: int(x), input().split())
	list1.append(a)
	list2.append(b)
for i in list1:
	k = 0
	while k < len(list2):
		if i == list2[k]:
			w += 1
		k += 1
print(w)


n = int(input())
count = 0
host = []
gues = []
for i in range(n):
	uni = input().split()
	host.append(uni[0])
	gues.append(uni[1])
for i in host:
	if i in gues:
		count = count + gues.count(i)
print(count)


import sys
from math import *
input = sys.stdin.readline
RI = lambda : [int(x) for x in sys.stdin.readline().strip().split()]
rw = lambda : input().strip().split()
from collections import defaultdict as df
import heapq
infinite = float('inf')
n = int(input())
d = {}
l = []
for i in range(n):
	(a, b) = RI()
	l.append(a)
	if b in d:
		d[b] += 1
	else:
		d[b] = 1
count = 0
for i in range(n):
	if l[i] in d:
		count += d[l[i]]
print(count)


noos = int(input())
a = []
b = []
for n in range(noos):
	c = str(input())
	c = c.split()
	a.append(c[0])
	b.append(c[1])
z = 0
for n in range(noos):
	y = b.count(a[n])
	z = z + y
print(z)


n = int(input())
host = []
guest = []
for i in range(n):
	(h, g) = map(int, input().split())
	host.append(h)
	guest.append(g)
total = 0
for i in range(n):
	for j in range(n):
		if host[i] == guest[j] and i != j:
			total += 1
print(total)


a = int(input())
b = []
c = 0
for j in range(a):
	b.append(list(map(int, input().split())))
for h in range(a):
	for l in range(a):
		if b[h][0] == b[l][1]:
			c = c + 1
print(c)


teams = int(input())
count = 0
host = []
guest = []
while count < teams:
	color = input()
	color = color.split(' ')
	host.append(color[0])
	guest.append(color[1])
	count += 1
times = 0
for x in guest:
	for y in host:
		if x == y:
			times += 1
		else:
			pass
print(times)


def change(a_list, b_list):
	k = 0
	if a_list[0] == b_list[1]:
		k += 1
	if a_list[1] == b_list[0]:
		k += 1
	return k
n = int(input())
game = []
k = 0
for i in range(n):
	game.append(list(map(int, input().strip().split(' '))))
for i in range(n - 1):
	for j in range(i + 1, n):
		k += change(game[i], game[j])
print(k)


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


n = int(input())
games = []
for i in range(n):
	games.append(input().split())
new_games = []
for i in range(len(games)):
	new_games.append(int(games[i][0]))
	new_games.append(int(games[i][1]))
home = []
away = []
for j in range(len(new_games)):
	if j % 2 == 0:
		home.append(new_games[j])
	else:
		away.append(new_games[j])
count = 0
for k in range(len(home)):
	for j in range(len(away)):
		if home[k] == away[j]:
			count += 1
		else:
			continue
print(count)


n = int(input())
list = []
for i in range(n):
	word = input().split(' ')
	list.append(word)
uni = 0
for i in range(n):
	for j in range(n):
		if int(list[i][0]) == int(list[j][1]):
			uni += 1
print(uni)


def main():
	cases = int(input())
	teams = []
	for _ in range(cases):
		teams.append(input().split(' '))
	res = 0
	for i in range(cases):
		for j in range(cases):
			if i != j:
				if teams[i][0] == teams[j][1]:
					res += 1
	print(res)
main()


import os
import sys

def log(*args, **kwargs):
	if os.environ.get('CODEFR'):
		print(*args, **kwargs)
n = int(input())
pairs = []
for i in range(n):
	pairs.append(tuple(map(int, input().split())))
r = 0
for i in range(n):
	for j in range(n):
		if i == j:
			continue
		if pairs[i][0] == pairs[j][1]:
			r += 1
print(r)


n = int(input())
h = []
g = []
m = 0
for i in range(n):
	(a, b) = map(int, input().split(' '))
	h.append(a)
	g.append(b)
for i in range(n):
	for j in range(n):
		if i == j:
			continue
		elif h[i] == g[j]:
			m += 1
		else:
			continue
print(m)


no_of_teams = int(input())
my_list = []
for x in range(no_of_teams):
	inp = input()
	colors = inp.split()
	my_list.append(colors)
counter = 0
for i in range(no_of_teams):
	for y in range(len(my_list)):
		if my_list[i][0] == my_list[y][1]:
			counter += 1
print(counter)


home = {}
away = {}
a = set()
for i in range(int(input())):
	(x, y) = map(int, input().split())
	a.add(x)
	a.add(y)
	if x in home:
		home[x] += 1
	else:
		home[x] = 1
	if y in away:
		away[y] += 1
	else:
		away[y] = 1
ans = 0
for i in a:
	if i in home and i in away:
		ans += home[i] * away[i]
print(ans)


gt = int(input())
h = {}
g = {}
for i in range(gt):
	(t, k) = map(int, input().split())
	h[t] = h[t] + 1 if t in h.keys() else 1
	g[k] = g[k] + 1 if k in g.keys() else 1
tr = 0
for i in h.keys():
	if i in g.keys():
		tr = tr + h[i] * g[i]
print(tr)


t = int(input())
mat = []
for _ in range(t):
	(l, r) = map(int, input().split())
	mat.append([l, r])
count = 0
for i in range(t):
	for j in range(t):
		if i != j:
			if mat[i][0] == mat[j][1]:
				count += 1
print(count)


pr = input()
n = int(pr)
i = 0
ai = []
hi = []
count = 0
while i < n:
	b = input()
	t = b.split()
	hi.append(int(t[0]))
	ai.append(int(t[1]))
	i = i + 1
i = 0
while i < n:
	j = 0
	while j < n:
		if ai[i] == hi[j]:
			count = count + 1
		j = j + 1
	i = i + 1
print(count)


n = int(input())
host = []
guest = []
for i in range(n):
	_ = input().split()
	host += [_[0]]
	guest += [_[1]]
result = 0
for x in host:
	result += guest.count(x)
print(result)


n = int(input())
(h, a) = ([], [])
for i in range(n):
	(w, e) = [x for x in input().split(' ')]
	h.append(w)
	a.append(e)
m = 0
for i in h:
	if i in a:
		m += a.count(i)
print(m)


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


n = int(input())
zidian = {}
ts = 0
lzhuchang = []
for i in range(n):
	(a, b) = [int(j) for j in input().split()]
	while (a, ts) in zidian:
		ts += 1
	zidian[a, ts] = b
	lzhuchang.append((a, ts))
lkechang = []
jieguo = 0
for zhuchangsehao in lzhuchang:
	for (k, v) in zidian.items():
		if zhuchangsehao == k:
			continue
		lkechang.append(v)
	for kechangsehao in lkechang:
		if zhuchangsehao[0] == kechangsehao:
			jieguo += 1
	lkechang.clear()
print(jieguo)


import collections
(a, b) = ([], [])
for _ in range(int(input())):
	(x, y) = map(int, input().split())
	a.append(x)
	b.append(y)
(c, d) = map(collections.Counter, (a, b))
print(sum((v * d[k] for (k, v) in c.items() if k in d)))


n = int(input())
a = []
h = []
for i in range(n):
	(x, y) = map(int, input().split())
	h.append(x)
	a.append(y)
ct = 0
Dict = {}
for i in a:
	Dict[i] = a.count(i)
for i in h:
	if i in Dict.keys():
		ct += Dict[i]
print(ct)


import sys

class Scanner:

	def __init__(self):
		self.current_tokens = []

	def remaining_tokens(self):
		return len(self.current_tokens)

	def nextline(self):
		assert self.remaining_tokens() == 0, 'Reading next line with remaining tokens'
		return input()

	def nexttokens(self):
		return self.nextline().split()

	def nexttoken(self):
		if len(self.current_tokens) == 0:
			self.current_tokens = self.nexttokens()
		assert self.remaining_tokens() > 0, 'Not enough tokens to parse.'
		return self.current_tokens.pop(0)

	def nextints(self, n=-1):
		if n == -1:
			return list(map(int, self.nexttokens()))
		else:
			return (self.nextint() for i in range(n))

	def nextint(self):
		return int(self.nexttoken())

def quit():
	sys.exit(0)
stdin = Scanner()
nextint = stdin.nextint
nextints = stdin.nextints
nextline = stdin.nextline
n = nextint()
t = []
for i in range(n):
	(h, a) = nextints(2)
	t.append([h, a])
c = 0
for i in range(n):
	for j in range(n):
		if i == j:
			continue
		h1 = t[i]
		h2 = t[j]
		if h1[0] == h2[1]:
			c += 1
print(c)


n = int(input())
m = []
count = 0
for i in range(n):
	l = list(map(int, input().split()))[:2]
	m.append(l)
for i in range(n):
	h = m[i][0]
	g = m[i][1]
	for j in range(i + 1, n):
		if h == m[j][1] and g == m[j][0]:
			count = count + 2
		elif h == m[j][1] and g != m[j][0]:
			count = count + 1
		elif h != m[j][1] and g == m[j][0]:
			count = count + 1
print(count)


def findMatching(teams):
	homes = []
	guests = []
	checked = []
	count = 0
	for team in teams:
		homes.append(str(team[0]))
		guests.append(str(team[1]))
	for home in homes:
		for guest in guests:
			if home == guest:
				count += 1
	return count
nums = int(input())
teams = []
for i in range(nums):
	listOfInputs = input().split()
	teams.append(listOfInputs)
print(findMatching(teams))


teams = int(input(''))
data = {}
ans = 0
for i in range(teams):
	temp = list(map(int, input('').split(' ')))
	data[i] = [temp[0], temp[1]]
	temp = []
for host in data:
	for guest in data:
		if host == guest:
			continue
		if data[guest][1] == data[host][0]:
			ans += 1
print(ans)


n = int(input())
ar = []
for i in range(n):
	(x, y) = map(int, input().split())
	ar.append([x, y])
c = 0
for i in range(len(ar)):
	for j in range(len(ar)):
		if i != j:
			if ar[i][0] == ar[j][1]:
				c += 1
print(c)


n = int(input())
a = [list(map(int, input().split())) for _ in range(n)]
count = 0
b = []
c = []
for i in a:
	for j in i:
		b.append(j)
for k in range(len(b)):
	for l in range(len(b)):
		if k % 2 == 1 and l % 2 == 0:
			if b[k] == b[l]:
				count = count + 1
				c.append(count)
				count = 0
print(sum(c))


x = int(input())
y = []
while x != 0:
	y = y + input().split()
	x = x - 1
a = y[1::2]
b = y[0::2]
k = 0
for i in b:
	k = a.count(i) + k
print(k)


n = int(input())
(chi, cai) = ([], [])
ccount = 0
for i in range(n):
	(hi, ai) = map(int, input().split())
	chi.append(hi)
	cai.append(ai)
for e in chi:
	ccount += cai.count(e)
print(ccount)


x = int(input())
home = []
away = []
for number in range(x):
	game = [int(a) for a in input().split()]
	home.append(game[0])
	away.append(game[1])
answer = 0
for numb in range(1, 101):
	answer += home.count(numb) * away.count(numb)
print(answer)


n = int(input())
arr = []
for i in range(n):
	d = input().split()
	arr.append(d)
ans = 0
for i in range(n):
	for j in range(n):
		if i != j and arr[i][0] == arr[j][1]:
			ans += 1
print(ans)


x = []
r = []
l = []
a = 0
for i in range(int(input())):
	x.append(input().split())
for d in x:
	r.append(int(d[0]))
	l.append(int(d[1]))
for m in r:
	a += l.count(m)
print(a)


n = int(input())
guest = []
home = []
for i in range(n):
	inn = list(map(int, input().split()))
	home.append(inn[0])
	guest.append(inn[1])
sol = 0
for i in home:
	if i in guest:
		sol = sol + guest.count(i)
print(sol)


n = int(input())
home = {}
guest = {}
numb = 0
for i in range(n):
	pole = input().split()
	if int(pole[0]) in home:
		home[int(pole[0])] += 1
	else:
		home[int(pole[0])] = 1
	if int(pole[1]) in guest:
		guest[int(pole[1])] += 1
	else:
		guest[int(pole[1])] = 1
for i in home:
	if i in guest:
		numb += home[i] * guest[i]
print(numb)


R = 0
home = []
guest = []
for i in range(int(input())):
	(huni, guni) = [int(u) for u in input().split()]
	home.append(huni)
	guest.append(guni)
for i in set(home):
	R += home.count(i) * guest.count(i)
print(R)


def main():
	teams = int(input())
	h = []
	a = []
	answer = 0
	for i in range(teams):
		team = input()
		h.append(list(map(int, team.split()))[0])
		a.append(list(map(int, team.split()))[1])
	for i in range(teams):
		for j in range(teams):
			if i != j and h[i] == a[j]:
				answer += 1
	print(answer)
main()


import time

def pickUniforms(hostUni, guestUnifs):
	dupl = 0
	hUnif = hostUni[0]
	for guestUnif in guestUnifs:
		gUnif = guestUnif[1]
		if hUnif == gUnif:
			dupl += 1
	return dupl

def solve():
	teams = int(input())
	games = teams * (teams - 1)
	teamUnifsMat = []
	for x in range(teams):
		teamUnif = [int(x) for x in input().split()]
		teamUnifsMat.append(teamUnif)
	start_time = time.time()
	qtyDupl = 0
	for (inx, y) in enumerate(teamUnifsMat):
		qtyDupl += pickUniforms(y, teamUnifsMat)
	print(qtyDupl)
solve()


n = int(input())
a = []
for i in range(n):
	a.append(list(map(int, input().split())))
c = 0
for i in range(len(a)):
	for j in range(len(a)):
		if j != i:
			home = a[i]
			guest = a[j]
			hd = a[i][0]
			gd = a[j][1]
			if hd == gd:
				c += 1
print(c)


hmdct = {}
awydct = {}
mts = int(input())
for _ in range(mts):
	unfms = list(map(int, input().split(' ')))
	if unfms[0] in hmdct.keys():
		hmdct[unfms[0]] += 1
	else:
		hmdct[unfms[0]] = 1
	if unfms[1] in awydct.keys():
		awydct[unfms[1]] += 1
	else:
		awydct[unfms[1]] = 1
fmts = 0
for each in hmdct.keys():
	if each in awydct.keys():
		fmts += hmdct[each] * awydct[each]
print(fmts)


n = int(input())
mp = {}
a = []
for i in range(n):
	(x, y) = map(int, input().split())
	a.append(x)
	mp[y] = mp.get(y, 0) + 1
ans = 0
for home in a:
	ans += mp.get(home, 0)
print(ans)


n = int(input())
data = []
for _ in range(n):
	data.append(list(map(int, input().split())))
cnt = 0
for home in range(len(data)):
	for away in range(len(data)):
		if home == away:
			continue
		if data[home][0] == data[away][1]:
			cnt += 1
print(cnt)


n = int(input())
a = list()
b = list()
out = 0
for i in range(n):
	temp = input().split()
	a.append(temp[0])
	b.append(temp[1])
for s in range(n):
	out += b.count(a[s])
print(out)


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


counter = int(input())
left = []
right = []
for _ in range(counter):
	(a, b) = map(int, input().split())
	left.append(a)
	right.append(b)
count = 0
for i in range(len(left)):
	for j in range(len(right)):
		if left[i] == right[j]:
			count += 1
print(count)


tot = int(input())
teams = []
tnum = 0
for _ in range(tot):
	teams.append(list(map(int, input().split())))
for _ in range(tot):
	for __ in range(tot):
		if teams[_][0] == teams[__][1]:
			tnum += 1
print(tnum)


(home_color, exit_color) = ({}, {})
(n, summ) = (int(input()), 0)
for i in range(n):
	(h, a) = [int(elem) for elem in input().split()]
	if not h in home_color:
		home_color[h] = 1
	else:
		home_color[h] += 1
	if not a in exit_color:
		exit_color[a] = 1
	else:
		exit_color[a] += 1
for elem in exit_color.keys():
	if elem in home_color.keys():
		summ += home_color[elem] * exit_color[elem]
print(summ)


n = int(input())
l = []
k = []
c = 0
d = 0
for i in range(n):
	(n1, n2) = map(int, input().split())
	l.append(n1)
	k.append(n2)
for i in range(n):
	if l[i] in k:
		c += k.count(l[i])
	if k[i] in l:
		d += l.count(k[i])
print(max(c, d))


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)


x = int(input(''))
list1 = []
list2 = []
count = 0
for c in range(x):
	(m, n) = map(int, input().split())
	list1.append(m)
	list2.append(n)
for i in range(x):
	for l in range(x):
		if list1[i] == list2[l]:
			count += 1
		else:
			pass
print(count)


n = int(input())
(h, a) = ([], [])
for _ in range(n):
	x = [int(x) for x in input().split()]
	h += [x[0]]
	a += [x[1]]
out = 0
for i in range(n):
	for j in range(n):
		if i != j and h[i] == a[j]:
			out += 1
print(out)


import sys

def i():
	return input()

def ii():
	return int(input())

def li():
	return input().split()

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


def solve(pairs):
	res = 0
	for i in pairs:
		for j in pairs:
			if i[0] == j[1]:
				res += 1
	return res
n = int(input())
l = []
for _ in range(n):
	l.append([int(x) for x in input().split()])
print(solve(l))


n = int(input())
list1 = []
for i in range(0, n, 1):
	list2 = [int(i) for i in input().split()]
	list1.append(list2)
m = 0
for i in range(0, n - 1, 1):
	for j in range(i + 1, n, 1):
		if list1[i][0] == list1[j][1]:
			m = m + 1
		if list1[i][1] == list1[j][0]:
			m = m + 1
print(m)


def main():
	n = int(input())
	home_colors = []
	away_colors = []
	counter = 0
	for i in range(n):
		(a, b) = [int(x) for x in input().split()]
		home_colors.append(a)
		away_colors.append(b)
	for i in range(n):
		for x in range(n):
			if home_colors[i] == away_colors[x]:
				counter += 1
	print(counter)
main()


n = int(input())
a = []
b = []
for i in range(n):
	s = input()
	c = s.split()
	a.append(c[0])
	b.append(c[1])
sum = 0
for i in range(n):
	j = 0
	while j < n:
		if j == i and j < n - 1:
			j += 1
		if a[i] == b[j]:
			sum += 1
		j += 1
print(sum)


n = int(input())
l = [[int(x) for x in input().split()] for i in range(n)]
m = 0
for i in range(n):
	for ii in range(n):
		if l[i][0] == l[ii][1]:
			m += 1
print(m)


n = int(input())
(a, b) = ([], [])
c = 0
for i in range(n):
	line = input().split()
	a.append(line[0])
	b.append(line[1])
for z in a:
	c += b.count(z)
print(c)


num_teams = int(input())
(homes, guests) = ([], [])
for i in range(num_teams):
	(h, g) = input().split()
	homes.append(h)
	guests.append(g)
print(sum((homes.count(i) for i in guests)))


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


import math
n = int(input())
start = []
end = {}
for _ in range(n):
	(a, b) = map(int, input().split())
	start.append(a)
	end[b] = end.get(b, 0) + 1
count = 0
for i in start:
	if i in end:
		count += end[i]
print(count)


n = int(input())
al = list()
bl = list()
count = 0
for i in range(n):
	(a, b) = map(int, input().split())
	al.append(a)
	bl.append(b)
for i in al:
	count = count + bl.count(i)
print(count)


team = int(input())
hlist = []
glist = []
ans = 0
for i in range(team):
	(h, g) = (int(v) for v in input().split())
	hlist.append(h)
	glist.append(g)
for j in range(len(hlist)):
	for k in range(len(glist)):
		if hlist[j] == glist[k]:
			ans += 1
print(ans)


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


n = int(input())
(home, guest) = ([], {})
for i in range(n):
	(t1, t2) = map(int, input().split())
	home.append(t1)
	if t2 not in guest:
		guest[t2] = 1
	else:
		guest[t2] += 1
count = 0
for i in home:
	if i in guest:
		count += guest[i]
print(count)


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


n = int(input())
ct = 0
(h, a) = ([None] * n, [None] * n)
for i in range(n):
	(h[i], a[i]) = map(int, input().split(' '))
for i in range(n):
	for j in range(n):
		if i != j and h[i] == a[j]:
			ct += 1
print(ct)


n = int(input())
hosts = []
guests = []
num = 0
for i in range(n):
	(a, b) = map(int, input().split())
	hosts.append(a)
	guests.append(b)
for host in hosts:
	for guest in guests:
		if host == guest:
			num += 1
print(num)


from sys import stdin, stdout

def sin():
	return stdin.readline().rstrip()

def listInput():
	return list(map(int, sin().split()))

def printBS(li):
	if not li:
		return
	for i in range(len(li) - 1):
		stdout.write('%d ' % li[i])
	stdout.write('%d\n' % li[-1])
n = int(sin())
(h, aw) = ([], [])
for i in range(n):
	(a, b) = listInput()
	h.append(a)
	aw.append(b)
ans = 0
for i in range(n):
	for j in range(n):
		if i == j:
			continue
		if h[i] == aw[j]:
			ans += 1
print(ans)


from collections import defaultdict
home_uniforms = defaultdict(int)
visiting_uniforms = defaultdict(int)
teams_count = int(input())
for i in range(teams_count):
	(home_uniform, visiting_uniform) = input().split()
	home_uniforms[home_uniform] += 1
	visiting_uniforms[visiting_uniform] += 1
res = 0
for (uniform_color, color_cnt) in home_uniforms.items():
	teams_with_same_uniform_color = visiting_uniforms.get(uniform_color)
	if teams_with_same_uniform_color:
		res += teams_with_same_uniform_color * color_cnt
print(res)


n = int(input())
a = []
for i in range(n):
	r = input()
	a.append(r)
f = 0
for i in range(n - 1):
	b = a[i]
	for j in range(len(b)):
		if b[j] == ' ':
			c = j
	for k in range(i + 1, n):
		d = a[k]
		for l in range(len(d)):
			if d[l] == ' ':
				e = l
		if b[:c] == d[e + 1:]:
			f += 1
		if b[c + 1:] == d[:e]:
			f += 1
print(f)


from sys import stdin
u = [x.rstrip().split() for x in stdin.readlines()][1:]
g = [x[1] for x in u]
print(sum((g.count(x[0]) for x in u)))


z = int(input())
s = []
for i in range(z):
	x = list(map(int, input().split()))
	s.append(x)
a = 0
for i in s:
	for o in s:
		if o == i:
			continue
		elif i[0] == o[1]:
			a += 1
print(a)


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


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


n = int(input())
l = []
e = []
for i in range(n):
	(a, b) = map(int, input().split())
	l.append(a)
	e.append(b)
w = 0
for i in range(n):
	w += e.count(l[i])
print(w)


t = input()
n = int(t)
homeJersey = []
awayJersey = []
count = 0
for i in range(n):
	color = input()
	temp = color.split()
	homeJersey.append(temp[0])
	awayJersey.append(temp[1])
for i in range(n):
	for j in range(n):
		if homeJersey[i] == awayJersey[j]:
			count += 1
print(count)


A = []
B = []
for i in range(int(input())):
	(a, b) = map(int, input().split())
	(A, B) = (A + [a], B + [b])
r = 0
for x in A:
	r += B.count(x)
print(r)


n = int(input())
l = []
for _ in range(n):
	(h, g) = map(int, input().split())
	l.append([h, g])
c = 0
for i in range(len(l)):
	for j in range(len(l)):
		if i == j:
			continue
		if l[i][1] == l[j][0]:
			c += 1
print(c)


(z, zz) = (input, lambda : list(map(int, z().split())))
zzz = lambda : [int(i) for i in stdin.readline().split()]
(szz, graph, mod, szzz) = (lambda : sorted(zz()), {}, 10 ** 9 + 7, lambda : sorted(zzz()))
from string import *
from re import *
from collections import *
from queue import *
from sys import *
from collections import *
from math import *
from heapq import *
from itertools import *
from bisect import *
from collections import Counter as cc
from math import factorial as f
from bisect import bisect as bs
from bisect import bisect_left as bsl
from itertools import accumulate as ac

def lcd(xnum1, xnum2):
	return xnum1 * xnum2 // gcd(xnum1, xnum2)

def prime(x):
	p = ceil(x ** 0.5) + 1
	for i in range(2, p):
		if x % i == 0 and x != 2 or x == 0:
			return 0
	return 1

def dfs(u, visit, graph):
	visit[u] = True
	for i in graph[u]:
		if not visit[i]:
			dfs(i, visit, graph)
l1 = []
l2 = []
n = int(z())
ans = 0
for _ in range(n):
	(a, b) = zz()
	l1.append(a)
	l2.append(b)
for i in l1:
	if i in l2:
		ans += l2.count(i)
print(ans)


n = int(input())
final = []
temp = n
while temp != 0:
	lst = []
	lst = list(map(int, input().split()))
	final.append(lst)
	temp -= 1
count = 0
for i in range(n):
	for j in range(n):
		if i == j:
			continue
		elif final[i][1] == final[j][0]:
			count += 1
print(count)


x = int(input())
list_home = list()
list_guest = list()
count = 0
for i in range(0, x):
	list1 = input().split(' ')
	list2 = [int(j) for j in list1]
	list_home.append(list2[0])
	list_guest.append(list2[1])
for i in list_home:
	count += list_guest.count(i)
print(count)


n = int(input())
a1 = []
a2 = []
count = 0
for i in range(n):
	(a, b) = map(int, input().split())
	a1.append(a)
	a2.append(b)
for i in range(n):
	for j in range(n):
		if i == j:
			pass
		elif a1[i] == a2[j]:
			count = count + 1
print(count)


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


n = int(input())
ar = []
count1 = 0
count2 = 0
for i in range(n):
	s = list(map(int, input().split()))
	ar.append(s)
for i in range(len(ar)):
	for j in range(len(ar)):
		if ar[j][1] == ar[i][0]:
			count1 = count1 + 1
for i in range(len(ar)):
	for j in range(len(ar)):
		if ar[j][0] == ar[i][1]:
			count2 = count2 + 1
print((count1 + count2) // 2)


x = int(input())
t = 0
c = []
d = []
for i in range(x):
	(n, y) = list(map(int, input().split()))
	c.append(n)
	d.append(y)
for i in range(x):
	for j in range(x):
		if c[i] == d[j]:
			t = t + 1
print(t)


num_teams = int(input())
list = []
count = 0
for x in range(num_teams):
	(home, away) = map(int, input().split())
	list.append(home)
	list.append(away)
for i in range(0, len(list), 2):
	j = list[i]
	for a in range(1, len(list), 2):
		b = list[a]
		if j == b:
			count += 1
print(count)


n = int(input())
uniforms = [[0 for x in range(2)] for y in range(n)]
result = 0
for i in range(n):
	uniforms[i][:] = [int(x) for x in input().split()]
for i in range(n):
	for j in range(n):
		if i == j:
			continue
		elif uniforms[i][0] == uniforms[j][1]:
			result += 1
print(result)


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


n = int(input())
s = []
x = []
w = 0
t = 0
r = 0
for i in range(n):
	(a, h) = map(int, input().split())
	s.append(a)
	x.append(h)
for i in range(n):
	d = []
	if s[i] in x:
		w = s[i]
		r = i
		for i in range(n):
			if x[i] == w:
				d.append(i)
		for i in range(len(d)):
			if d[i] != r:
				t = t + 1
print(t)


n = int(input())
c = 0
matrix = [[int(x) for x in input().split()] for i in range(n)]
trans = []
for i in range(2):
	trans.append([row[i] for row in matrix])
for i in range(n):
	for j in range(n):
		if trans[0][i] == trans[1][j]:
			c += 1
print(c)


n = int(input())
h = [0] * n
g = [0] * n
for i in range(n):
	(h[i], g[i]) = input().strip().split()
s = 0
for i in range(n):
	for j in range(n):
		if h[i] == g[j]:
			s += 1
print(s)


from collections import defaultdict

def solve():
	n = int(input())
	h_d = defaultdict(lambda : 0)
	a_d = defaultdict(lambda : 0)
	for i in range(n):
		(h, a) = map(int, input().split())
		h_d[h] += 1
		a_d[a] += 1
	res = 0
	for k in h_d:
		res += h_d[k] * a_d[k]
	print(res)
solve()


def solve(host, guest):
	ans = 0
	for i in host:
		ans += guest.count(i)
	return ans
host = []
guest = []
for i in range(int(input())):
	(a, b) = list(map(int, input().split(' ')))
	host.append(a)
	guest.append(b)
print(solve(host, guest))


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


n = int(input())
l = []
c = 0
while c < n:
	m = input()
	l += [m]
	c += 1
l1 = []
l2 = []
a = 0
for i in l:
	i = i.split()
	l1 += [int(i[0])]
	l2 += [int(i[-1])]
for i in l1:
	for j in l2:
		if i == j:
			a += 1
print(a)


n = int(input())
array = []
count = 0
for i in range(n):
	new_array = list(map(int, input().split()))
	array.append(new_array)
for i in range(n):
	for j in range(n):
		if i == j:
			continue
		if array[i][0] == array[j][1]:
			count += 1
print(count)


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)


from collections import Counter
teams = int(input())
home = Counter()
guest = Counter()
for t in range(teams):
	(h, g) = input().split()
	home[int(h)] += 1
	guest[int(g)] += 1
overlaps = 0
for color in home:
	overlaps += home[color] * guest[color]
print(overlaps)


n = int(input())
list_of_matches = []
list_of_matches.append(list(map(int, input().split())))
output = 0
for i in range(n - 1):
	new_team = list(map(int, input().split()))
	for colors in list_of_matches:
		if new_team[1] == colors[0]:
			output += 1
		if new_team[0] == colors[1]:
			output += 1
	list_of_matches.append(new_team)
print(output)


from sys import stdin
n = int(stdin.readline().strip())
teams = []
for x in range(n):
	teams.append([int(x) for x in stdin.readline().strip().split(' ')])

def solution(n, teams):
	res = 0
	h = []
	g = []
	for x in teams:
		h.append(x[0])
		g.append(x[1])
	for x in h:
		if g.__contains__(x):
			res += g.count(x)
	return res
print(solution(n, teams))


n = int(input())
home = []
away = []
while n > 0:
	(h, a) = map(int, input().split())
	home.append(h)
	away.append(a)
	n -= 1
cnt = 0
for x in home:
	for y in away:
		if x == y:
			cnt += 1
		else:
			pass
print(cnt)


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


n = int(input())
clothes = []
while n > 0:
	temp = list(map(int, input().split()))
	clothes.append(temp)
	n -= 1
counter = 0
i = 0
while i < len(clothes):
	j = 0
	temp = clothes[i][0]
	while j < len(clothes):
		if j != i:
			if clothes[j][1] == temp:
				counter += 1
		j += 1
	i += 1
print(counter)


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


n = int(input())
teams = []
while n:
	nums = list(map(int, input().split()))
	teams.append(nums)
	n -= 1
count = 0
for i in range(len(teams)):
	for j in range(i + 1, len(teams)):
		if teams[i][1] == teams[j][0] and teams[i][0] == teams[j][1]:
			count += 2
		elif teams[i][1] == teams[j][0] or teams[i][0] == teams[j][1]:
			count += 1
print(count)


n = int(input())
team_list = []
for i in range(n):
	team_list.append(input().split())
s = list(map(list, zip(*team_list)))
count = 0
for i in range(len(s[0])):
	count += s[1].count(s[0][i])
print(count)


n = int(input())
colors = [0] * n
for i in range(n):
	colors[i] = list(map(int, input().split()))
N = 0
for i in range(n):
	for k in range(n):
		if colors[i][1] == colors[k][0]:
			N += 1
print(N)


test = int(input())
dc_l = {}
dc_r = {}
count = 0
for t in range(0, test):
	arr = list(map(int, input().split()))
	if arr[0] not in dc_l:
		dc_l[arr[0]] = 1
	else:
		dc_l[arr[0]] += 1
	if arr[1] not in dc_r:
		dc_r[arr[1]] = 1
	else:
		dc_r[arr[1]] += 1
	if arr[0] in dc_r:
		count += dc_r[arr[0]]
	if arr[1] in dc_l:
		count += dc_l[arr[1]]
print(count)


n = int(input())
l = []
j = []
for i in range(n):
	(n, m) = [int(x) for x in input().split()]
	l.append(n)
	j.append(m)
s = 0

def shu(l, i):
	if i not in l:
		return 0
	else:
		d = 0
		while i in l:
			l = l[l.index(i) + 1:]
			d += 1
		return d
for i in j:
	s += shu(l, i)
print(s)


from collections import Counter
l1 = []
l2 = []
for _ in range(int(input())):
	(x, y) = map(int, input().split(' '))
	l1.append(x)
	l2.append(y)
l1.sort()
l2.sort()
l1 = Counter(l1)
l2 = Counter(l2)
count = 0
for i in l1:
	for j in l2:
		if i == j:
			count = count + l1[i] * l2[j]
			break
print(count)


class team:

	def __init__(self, home, guest):
		self.home = home
		self.guest = guest

	def match(self, player):
		if self.home == player.guest:
			return True
		return False
n = int(input())
l = []
m = 0
for i in range(n):
	(a, b) = map(int, input().split())
	l.append(team(a, b))
for a in l:
	for b in l:
		if a.match(b):
			m += 1
print(m)


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


teams = int(input())
colours = []
for i in range(teams):
	colours.append(list(map(int, input().split())))
clashes = 0
for i in range(teams):
	for j in range(teams):
		if i == j:
			continue
		if colours[i][0] == colours[j][1]:
			clashes += 1
print(clashes)


n = int(input())
tab = []
for i in range(n):
	(h, a) = [int(x) for x in input().split()]
	tab.append([h, a])
i = 0
suma = 0
while i != n:
	for j in range(len(tab)):
		if i != j:
			if tab[i][0] == tab[j][1]:
				suma += 1
	i += 1
print(suma)


n = int(input())
home = []
away = []
for i in range(n):
	k = input().split()
	home.append(k[0])
	away.append(k[1])
c = 0
for i in range(n):
	for j in range(n):
		if i != j:
			if home[i] == away[j]:
				c += 1
print(c)


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

def countInterSec(list1, list2):
	count = 0
	for i in range(len(list1)):
		for j in range(len(list2)):
			if list1[i] == list2[j]:
				count += 1
	return count
print(countInterSec(homeKits, awayKits))


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


def f():
	x = int(input())
	home = list()
	away = list()
	for _ in range(x):
		(a, b) = map(int, input().split())
		home.append(a)
		away.append(b)
	t = 0
	for c in home:
		t += away.count(c)
	print(t)
f()


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


n = int(input())
i = 0
arr = []
arr1 = []
while i < n:
	(a, b) = [int(i) for i in input().split()]
	arr.append(a)
	arr1.append(b)
	i += 1
z = 0
count = 0
for x in arr1:
	z = 0
	while z < len(arr):
		if x == arr[z]:
			count += 1
		z += 1
print(count)


c = int(input())
coms = []
for i in range(c):
	coms.append(input().split(' '))
res = 0
for k in range(c):
	for j in range(c):
		if k != j and coms[k][0] == coms[j][1]:
			res += 1
print(res)


x = []
x1 = 0
s = 0
m = 2
n = int(input())
for i in range(n):
	(h, a) = map(int, input().split())
	x.append([h, a])
for j in range(n):
	for i in range(n):
		if x[j][0] == x[i][1]:
			s += 1
print(s)


t = int(input())
h_arr = []
g_arr = []
for i in range(t):
	(h, g) = [int(x) for x in input().split()]
	h_arr.append(h)
	g_arr.append(g)
count = 0
for j in h_arr:
	count += g_arr.count(j)
print(count)


n = int(input())
home_cloths = {}
outfit = {}
for i in range(n):
	(home, out) = map(int, input().split())
	home_cloths[home] = home_cloths.get(home, 0) + 1
	outfit[out] = outfit.get(out, 0) + 1
changes = 0
for dress in home_cloths:
	changes += home_cloths[dress] * outfit.get(dress, 0)
print(changes)


arr_x = []
arr_y = []
for _ in range(int(input())):
	(x, y) = map(int, input().split())
	arr_x.append(x)
	arr_y.append(y)
cnt = 0
for i in arr_y:
	cnt += arr_x.count(i)
print(cnt)


n = int(input())
arr1 = []
arr2 = []
c = 0
for i in range(n):
	array = list(map(int, input().strip().split()))
	arr1.append(array[0])
	arr2.append(array[1])
for i in arr1:
	if i in arr2:
		c += arr2.count(i)
print(c)


hc = []
gc = []
c = 0
for _ in range(int(input())):
	(h, g) = input().split()
	hc.append(h)
	gc.append(g)
for g in gc:
	c += hc.count(g)
print(c)


n = int(input())
arr1 = []
arr2 = []
ans = 0
for _ in range(n):
	(x, y) = map(int, input().split(' '))
	arr1.append(x)
	arr2.append(y)
for i in range(len(arr1)):
	if arr1[i] in arr2:
		ans += arr2.count(arr1[i])
print(ans)


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


n = int(input())
kits = []
for i in range(0, n):
	kits.append(tuple(input().split()))
matches = 0
for i in range(0, len(kits) - 1):
	for j in range(i + 1, len(kits)):
		if kits[i][0] == kits[j][1]:
			matches += 1
		if kits[i][1] == kits[j][0]:
			matches += 1
print(matches)


n = int(input())
ld = []
lv = []
o = 0
for i in range(n):
	b = list(map(int, input().split()))
	ld.append(b[0])
	lv.append(b[1])
for i in range(len(ld)):
	r = lv.count(ld[i])
	if r > 0:
		o += r
	else:
		continue
print(o)


another = []
count = 0
for i in range(int(input())):
	first = [int(x) for x in input().split()]
	another.append(first)
for j in another:
	for k in another:
		if j == k:
			continue
		elif j[0] == k[1]:
			count += 1
print(count)


n = int(input())
a = []
count = 0
for _ in range(n):
	b = tuple(input().split())
	a.append(b)
for i in range(n):
	for j in range(n):
		if a[i][0] == a[j][1]:
			count += 1
print(count)


games = int(input())
dress = [input().split(' ') for i in range(games)]
count = 0
for i in range(games):
	for j in range(games):
		if dress[i][0] == dress[j][1]:
			count += 1
print(count)


import re
n = int(input())
ref = re.compile('\\d{3}|\\d\\d|\\d')
l = []
for i in range(n):
	i = input()
	num = ref.findall(i)
	l = l + [num]
c = 0
for u in range(n):
	s = l.copy()
	s.remove(l[u])
	for r in range(n - 1):
		if l[u][0] == s[r][1]:
			c += 1
print(c)


teams = int(input())
games = teams * (teams - 1)
colors = []
for i in range(teams):
	temp = input().split(' ')
	colors.append([int(temp[0]), int(temp[1])])
different_color = 0
for j in range(teams):
	for k in range(teams):
		if k != j:
			if colors[j][0] == colors[k][1]:
				different_color += 1
print(different_color)


n = int(input())
home = []
guest = []
for j in range(n):
	s = input()
	n1 = [int(i) for i in s.split()]
	home.append(n1[0])
	guest.append(n1[1])
count = 0
for i in range(n):
	for j in range(n):
		if home[i] == guest[j]:
			count += 1
print(count)


host = []
guest = []
for i in range(int(input())):
	(Host, Guest) = map(int, input().split())
	host.append(Host)
	guest.append(Guest)
time = 0
for i in range(len(host)):
	for j in range(len(guest)):
		if j != i:
			if guest[i] == host[j]:
				time += 1
print(time)


n = int(input())
h = []
g = []
ans = 0
for u in range(n):
	(H, A) = map(int, input().split())
	h.append(H)
	g.append(A)
for j in range(n):
	for k in range(n):
		if j == k:
			continue
		elif h[j] == g[k]:
			ans += 1
print(ans)


x = int(input())
a = []
b = []
for i in range(x):
	z = input().split()
	a += [z[0]]
	b += [z[1]]
y = 0
for i in a:
	for j in b:
		if i == j:
			y += 1
print(y)


(al, bl, ans) = ([], [], 0)
for _ in range(int(input())):
	(a, b) = map(int, input().split())
	al.append(a)
	bl.append(b)
for i in range(len(bl)):
	c = al.count(bl[i])
	ans += c
print(ans)


from sys import stdin as cin
n = int(cin.readline().strip())
count = 0
(home, away) = ([], [])
for _ in range(n):
	kit = cin.readline().strip().split()
	home.append(kit[0])
	away.append(kit[1])
for team1 in home:
	for team2 in away:
		if team1 == team2:
			count += 1
print(count)


n = input()
list_host = []
list_guest = []
for i in range(int(n)):
	(a, b) = map(int, input().split())
	list_host.append(a)
	list_guest.append(b)
counter = 0
for i in list_host:
	for j in list_guest:
		if i == j:
			counter += 1
print(counter)


n_teams = int(input())
teams = []
n_unnatural = 0
for i in range(n_teams):
	teams.append(list(map(int, input().split(' '))))
for (i, team) in enumerate(teams):
	if i == len(teams) - 1:
		break
	(h, g) = team
	for check_team in teams[i + 1:]:
		if h == check_team[1]:
			n_unnatural += 1
		if g == check_team[0]:
			n_unnatural += 1
print(n_unnatural)


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())
teams = []
cnt = 0
for i in range(n):
	(x, y) = input().split()
	teams.append([x, y])
for i in range(n):
	for k in range(n):
		if teams[i][0] == teams[k][1] and i != k:
			cnt += 1
print(cnt)


n = int(input())
(h, g) = ([], [])
cnt = 0
for i in range(n):
	t = list(map(int, input().split()))
	h.append(t[0])
	g.append(t[1])
for j in h:
	cnt += g.count(j)
print(cnt)


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


n = int(input())
m = []
p = []
for i in range(n):
	l = input()
	l = l.split()
	m.append(int(l[0]))
	p.append(int(l[1]))
c = 0
for i in range(n):
	for j in range(n):
		if m[j] == p[i]:
			c = c + 1
print(c)


n = int(input())
home_forms = []
entire_forms = []
count = 0
for i in range(n):
	(f1, f2) = map(int, input().split())
	home_forms.append(f1)
	entire_forms.append(f2)
for i in range(n):
	for j in range(n):
		if home_forms[i] == entire_forms[j] and (not i == j):
			count += 1
print(count)


n = int(input())
cnt = 0
dom = [0 for i in range(n)]
nedom = [0 for i in range(n)]
for i in range(n):
	(dom[i], nedom[i]) = map(int, input().split())
for i in range(n):
	for j in range(n):
		if i != j:
			if dom[i] == nedom[j]:
				cnt += 1
print(cnt)


a = int(input())
l1 = []
k = 0
l2 = []
for i in range(a):
	(b, c) = map(int, input().split())
	l1.append(b)
	l2.append(c)
for i in range(0, a):
	for j in range(0, a):
		if l1[i] == l2[j]:
			k += 1
print(k)


n = int(input())
s = []
for i in range(n):
	ss = [int(x) for x in input().split()]
	s.append(ss)
p = 0
for i in range(0, n):
	for j in range(0, n):
		if s[i][0] == s[j][1]:
			p += 1
print(p)


k = int(input())
c = []
sum = 0
for i in range(k):
	b = [int(b) for b in input().split()]
	c.append(b)
for x in range(k):
	for y in range(2):
		if x < k - 1 and y < 1:
			for m in range(1, k - x):
				if c[x][y] == c[x + m][y + 1]:
					sum = sum + 1
		if x < k - 1 and y == 1:
			for m in range(1, k - x):
				if c[x][y] == c[x + m][0]:
					sum = sum + 1
print(sum)


from collections import defaultdict
n = int(input())
h = defaultdict(int)
a = defaultdict(int)
for i in range(n):
	(x, y) = map(int, input().split())
	h[x] += 1
	a[y] += 1
count = 0
for i in h.keys():
	if i in a:
		count += h[i] * a[i]
print(count)


n = int(input())
matrix = []
count = 0
for _ in range(n):
	(h, g) = map(int, input().split())
	matrix.append([h, g])
for i in matrix:
	for j in matrix:
		if i == j:
			continue
		elif i[0] == j[1]:
			count += 1
print(count)


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


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


n = int(input())
nl = []
for i in range(n):
	(p, q) = map(int, input().split())
	nl.append(p)
	nl.append(q)
hl = nl[0:len(nl) + 1:2]
al = nl[1:len(nl) + 1:2]
ans = 0
for i in range(0, n):
	for j in range(0, n):
		if i != j and hl[i] == al[j]:
			ans += 1
print(ans)


n = int(input())
a = []
kol = 0
for i in range(n):
	(z, t) = map(int, input().split())
	a.append([z, t])
for i in range(n - 1):
	for j in range(i + 1, n):
		if a[i][0] == a[j][1]:
			kol += 1
		if a[i][1] == a[j][0]:
			kol += 1
print(kol)


a = int(input())
A = []
B = []
c = 0
for i in range(a):
	b = input().split()
	A.append(b[0])
	B.append(b[1])

def cz(x, Y):
	d = 0
	for i in Y:
		if i == x:
			d += 1
	return d
e = 0
for i in A:
	e += cz(i, B)
print(e)


n = int(input())
teams = []
for i in range(n):
	x = input()
	h = int(x.split()[0])
	g = int(x.split()[1])
	teams.append([h, g])
count = 0
for i in range(n):
	z = teams[:i] + teams[i + 1:]
	for j in range(n - 1):
		if z[j][1] == teams[i][0]:
			count += 1
print(count)


import sys
n = int(input())
host = dict()
guest = dict()
for i in range(n):
	(h, g) = map(int, sys.stdin.readline().split())
	if h in host:
		host[h] += 1
	else:
		host[h] = 1
	if g in guest:
		guest[g] += 1
	else:
		guest[g] = 1
ans = 0
for h in host:
	if h in guest:
		ans += host[h] * guest[h]
print(ans)


(h, a) = ([], [])
for _ in range(int(input())):
	(x, y) = map(int, input().strip().split())
	h.append(x)
	a.append(y)
k = 0
for i in range(len(h)):
	for j in range(len(a)):
		if a[i] == h[j]:
			k += 1
print(k)


n = int(input())
(h, a) = ([], [])
for i in range(n):
	s = [int(x) for x in input().split(' ')]
	h += [s[0]]
	a += [s[1]]
x = 0
for i in range(n):
	x += len([0 for j in a[i:n] if j == h[i]])
	x += len([0 for j in h[i:n] if j == a[i]])
print(x)


home = []
away = []
output = 0
n = int(input())
for i in range(n):
	(h, a) = map(int, input().split())
	home.append(h)
	away.append(a)
for elements1 in home:
	for elements2 in away:
		if elements1 == elements2:
			output += 1
print(output)


n = int(input())
counter = 0
h_list = []
a_list = []
for i in range(n):
	(h, a) = (int(j) for j in input().split())
	h_list.append(h)
	a_list.append(a)
for h in h_list:
	counter += a_list.count(h)
print(counter)


s = input()
h = []
g = []
for i in range(int(s)):
	s = input().split(' ')
	h.append(int(s[0]))
	g.append(int(s[1]))
sum = 0
for i in h:
	sum = sum + g.count(i)
print(sum)


n = int(input())
t = []
a = 0
for i in range(n):
	(b, m) = [int(x) for x in input().split()]
	t.append((b, m))
for i in range(n):
	for k in range(n):
		if i != k and t[i][0] == t[k][1]:
			a += 1
print(a)


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


t = int(input())
dic1 = dict()
dic2 = dict()
for j in range(t):
	(a, b) = map(int, input().split(' '))
	if a in dic1.keys():
		dic1[a] += 1
	else:
		dic1[a] = 1
	if b in dic2.keys():
		dic2[b] += 1
	else:
		dic2[b] = 1
sum1 = 0
for i in dic1.keys():
	if i in dic2.keys():
		sum1 += dic1[i] * dic2[i]
print(sum1)


n = int(input())
team = []
count = 0
for i in range(n):
	team_colour = list(map(int, input().split()))
	team.append(team_colour)
for i in list(range(n)):
	for j in list(range(n)):
		if i == j:
			continue
		if team[i][0] == team[j][1]:
			count += 1
print(count)


n = int(input())
teams = []
pairs = {}
for _ in range(n):
	(h, a) = map(int, input().split())
	teams.append(h)
	pairs[a] = pairs.get(a, 0) + 1
count = 0
for t in teams:
	count += pairs.get(t, 0)
print(count)


HOME = []
GUEST = []
N = int(input())
for _ in range(N):
	TMP = input().split()
	HOME.append(TMP[0])
	GUEST.append(TMP[1])
C = 0
for _ in range(N):
	if GUEST[_] in HOME:
		C += HOME.count(GUEST[_])
print(C)


t = int(input())
count = 0
teams = []
for i in range(t):
	(a, b) = map(int, input().split())
	teams.append([a, b])
for i in range(len(teams)):
	for j in range(len(teams)):
		if i != j and teams[i][0] == teams[j][1]:
			count += 1
print(count)


n = int(input())
count = 0
s = [[0, 0]] * n
for i in range(n):
	s[i] = [int(i) for i in input().split(' ')]
i = 0
while i < n:
	j = 0
	while j < n:
		if i != j:
			if s[i][0] == s[j][1]:
				count += 1
		j += 1
	i += 1
print(count)


teams = int(input())
home = ['home'] * teams
guest = ['guest'] * teams
for c in range(teams):
	color = input().split(' ')
	home[c] = color[0]
	guest[c] = color[1]
count = 0
for homecolor in home:
	count += guest.count(homecolor)
print(count)


teams = int(input())
host = []
guest = []
counter = 0
for x in range(teams):
	colors = input().split()
	host.append(colors[0])
	guest.append(colors[1])
for x in host:
	for y in guest:
		if x == y:
			counter += 1
print(counter)


n = int(input())
s = n
H = []
A = []
while s > 0:
	(h, a) = map(int, input().split())
	H += [h]
	A += [a]
	s -= 1
count_ = 0
for i in H:
	count_ += A.count(i)
print(count_)


def game(n):
	counter = 0
	i = 0
	list1 = []
	list2 = []
	for i in range(n):
		inp = list(map(str, input().strip().split()))
		list1.append(inp[0])
		list2.append(inp[1])
	for j in range(n):
		counter += list2.count(list1[j])
	return counter
n = int(input())
print(game(n))


n = int(input())
o = []
for i in range(n):
	(x, y) = [int(i) for i in input().split()]
	o.append((x, y))
sum = 0
for i in range(n):
	for j in range(i + 1, n):
		if o[i][0] == o[j][1] and o[i][1] == o[j][0]:
			sum += 2
		elif o[i][1] == o[j][0] or o[i][0] == o[j][1]:
			sum += 1
print(sum)


home = []
away = []
count = 0
for i in range(int(input())):
	(a, b) = map(int, input().split())
	home.append(a)
	away.append(b)
for i in home:
	if i in away:
		count += away.count(i)
print(count)


num_teams = int(input())
num_games = num_teams * (num_teams - 1)
home = []
guest = []
for i in range(num_teams):
	(h, g) = input().split()
	home.append(int(h))
	guest.append(int(g))
num_events = 0
for h in home:
	for g in guest:
		if h == g:
			num_events += 1
print(num_events)


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


counter = 0
n = int(input())
in_put = []
for i in range(n):
	in_put.append(str(input()).split(' '))
	i += 1
for l in in_put:
	for r in in_put:
		if l[0] == r[1]:
			counter += 1
print(counter)


import sys
idx = 0
num = 0
team_colors = []
for line in sys.stdin:
	if not idx:
		num = int(line)
	else:
		new_line = [int(i) for i in line.split()]
		team_colors.append(new_line)
	if idx >= num:
		break
	idx += 1
conflicts = 0
for i in team_colors:
	for j in team_colors:
		if i[0] == j[1]:
			conflicts += 1
print(conflicts)


homeTeam = []
guestTeam = {}
for _ in range(int(input())):
	(h, g) = map(int, input().split())
	homeTeam.append(h)
	guestTeam[g] = guestTeam.get(g, 0) + 1
ans = 0
for i in homeTeam:
	ans += guestTeam.get(i, 0)
print(ans)


tot_tea = int(input())
home_col = []
gues_col = []
count = 0
while tot_tea:
	col = input()
	col_l = col.split(' ')
	home_col.append(col_l[0])
	gues_col.append(col_l[1])
	tot_tea = tot_tea - 1
for i in range(0, len(home_col)):
	for j in range(0, len(home_col)):
		if i != j:
			if home_col[i] == gues_col[j]:
				count = count + 1
print(count)


a = int(input())
list1 = []
list2 = []
sum = 0
for i in range(a):
	(host, guest) = map(int, input().split())
	list1.append(host)
	list2.append(guest)
for i in range(len(list1)):
	for j in range(len(list2)):
		if list1[i] == list2[j]:
			sum += 1
print(sum)


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


n = int(input())
home = []
guest = []
for i in range(n):
	string = input().split(' ')
	home.append(string[0])
	guest.append(string[1])
count = 0
for i in range(n):
	for j in range(n):
		if i != j and home[i] == guest[j]:
			count += 1
print(count)


n = int(input())
matrix = []
for i in range(n):
	a_i = [int(x) for x in input().split()]
	matrix.append(a_i)
col1 = []
col2 = []
for i in range(n):
	col1.append(matrix[i][0])
for i in range(n):
	col2.append(matrix[i][1])
num = 0
for i in col1:
	if i in col2:
		num += col2.count(i)
print(num)


n = int(input())
l1 = []
l2 = []
sum = 0
for i in range(n):
	l = input().split()
	l1.append(l[0])
	l2.append(l[1])
s = set(l1)
for i in s:
	sum += l1.count(i) * l2.count(i)
print(sum)


n = int(input())
lis = []
ncount = 0
for i in range(n):
	lis.append([int(x) for x in input().split()])
for li in lis:
	for ss in lis:
		if li[0] == ss[1]:
			ncount += 1
print(ncount)


n = int(input())
kit = [[j for j in list(map(int, input().split()))] for i in range(n)]
count = 0
kit1 = []
kit2 = []
for i in range(n):
	kit1.append(kit[i][0])
	kit2.append(kit[i][1])
for i in range(len(kit1)):
	for j in range(len(kit2)):
		if kit1[i] == kit2[j]:
			count += 1
print(count)


n = int(input())
J = [list(map(int, input().split(' ')))[:n] for i in range(n)]
count = 0
if n >= 2 and n <= 30:
	for i in range(0, n):
		for j in range(0, n):
			if J[i][0] == J[j][1]:
				count += 1
print(count)


n = int(input())
a = []
c = 0
for i in range(n):
	a.append(list(map(int, input().split(' '))))
for i in range(n):
	t = list(a)
	t.remove(a[i])
	for k in range(n - 1):
		if a[i][0] == t[k][1]:
			c = c + 1
print(c)


from collections import Counter
n = int(input())
home = Counter()
away = Counter()
for i in range(n):
	(h, a) = map(int, input().split())
	home[h] += 1
	away[a] += 1
	sm = 0
for key in home.keys():
	t = home[key] * away[key]
	sm += t
print(sm)


x = int(input())
h_list = []
a_list = []
ans = 0
for _ in range(x):
	(h, a) = input().split()
	h_list.append(h)
	a_list.append(a)
for i in a_list:
	for j in h_list:
		if i == j:
			ans += 1
print(ans)


n = int(input())
g = 0
hostColors = []
guestColors = []
for i in range(n):
	(h, a) = [x for x in input().split()]
	hostColors.append(h)
	guestColors.append(a)
for color in guestColors:
	g += hostColors.count(color)
print(g)