fifa-4

Consider a football tournament where n teams participate. Each team has two football kits: for home games, and for away games. The kit for home games of the i-th team has color xi and the kit for away games of this team has color yi (xi ≠ yi).

In the tournament, each team plays exactly one home game and exactly one away game with each other team (n(n - 1) games in total). The team, that plays the home game, traditionally plays in its home kit. The team that plays an away game plays in its away kit. However, if two teams has the kits of the same color, they cannot be distinguished. In this case the away team plays in its home kit.

Calculate how many games in the described tournament each team plays in its home kit and how many games it plays in its away kit.

Input

The first line contains a single integer n (2 ≤ n ≤ 10^5) — the number of teams. Next n lines contain the description of the teams. The i-th line contains two space-separated numbers xi, yi (1 ≤ xi, yi ≤ 10^5; xi ≠ yi) — the colour numbers for the home and away kits of the i-th team.

Output

For each team, print on a single line two space-separated integers — the number of games this team is going to play in home and away kits, correspondingly. Print the answers for the teams in the order they appeared in the input.
Register for IndiaHacksSAMPLE INPUT
3
1 2
2 1
1 3

SAMPLE OUTPUT
3 1
4 0
2 2

Register for IndiaHacks

Source: hackerearth | Difficulty: EASY


Solutions:
n = int(input())

h = [0 for i in range(n)]
a = [0 for i in range(n)]

for i in range(n):
	w = input().split(" ")
	h[i] = int(w[0])
	a[i] = int(w[1])
 
home = [0 for i in range(n)]
away = [0 for i in range(n)]
hc ={}
ac = {}

t = (n*(n-1))/2+1
for i in range(n):
	if h[i] not in hc:
		hc[h[i]] = 0
	if a[i] not in ac:
		ac[a[i]] = 0
	hc[h[i]] += 1
	ac[a[i]] += 1

for i in range(n):
	home[i] = n-1
	if a[i] in hc:
		home[i] += hc[a[i]] 
	#if a[i] in hc:
	#	home[i] += hc[a[i]]
	#home[i] += n - ac[h[i]] - 1
	away[i] = n - 1 
	if a[i] in hc:
		away[i] -= hc[a[i]]

for i in range(n):
	print(home[i],away[i])


from collections import Counter
H, A = [], []
n = int(input())
for i in range(n):
	h, a = list(map(int, input().split()))
	H.append(h)
	A.append(a)
m = Counter(H)
for i in range(n):
	t = m[A[i]]
	y = n - 1 - t
	x = n - 1 + t
	print(x, y)


t = int(input(""))

team = [[] for i in range(2)]
played = [[] for i in range(2)]
home_kit = {}


for i in range(t):
	temp = input("").rstrip().split(' ')
	team[0].append(int(temp[0]))
	team[1].append(int(temp[1]))
	played[0].append(0)
	played[1].append(0)

	if int(temp[0]) not in home_kit:
		home_kit[int(temp[0])] = 1
	else:
		home_kit[int(temp[0])] += 1

for i in range(t):
	played[1][i] = played[0][i] = t - 1

	
	if team[1][i] in home_kit:
		played[1][i] -= home_kit[team[1][i]]
		played[0][i] += home_kit[team[1][i]]


for i in range(t):
	print(played[0][i], end=' ')
	print(played[1][i])   
	


n = int(input())

h = [0 for i in range(n)]
a = [0 for i in range(n)]

for i in range(n):
	w = input().split(" ")
	h[i] = int(w[0])
	a[i] = int(w[1])
 
home = [0 for i in range(n)]
away = [0 for i in range(n)]
hc ={}
ac = {}

t = (n*(n-1))/2+1
for i in range(n):
	if h[i] not in hc:
		hc[h[i]] = 0
	if a[i] not in ac:
		ac[a[i]] = 0
	hc[h[i]] += 1
	ac[a[i]] += 1

for i in range(n):
	home[i] = n-1
	if a[i] in hc:
		home[i] += hc[a[i]] 
	#if a[i] in hc:
	#	home[i] += hc[a[i]]
	#home[i] += n - ac[h[i]] - 1
	away[i] = n - 1 
	if a[i] in hc:
		away[i] -= hc[a[i]]

for i in range(n):
	print(home[i],away[i])