We are to compute for each team the number of games it plays in home kit and away kit. The tournament schedule: each pair of distinct teams (i, j) plays two games: one where i is home and j is away, and one where j is home and i is away. In each game, the home team wears its home kit (color xi for team i). The away team normally wears its away kit (color yi for team i). However, if the home team's home kit color equals the away team's away kit color, then they cannot be distinguished, so the away team plays in its home kit instead (so both teams wear home kits? Actually: "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." The condition: the two kits (home team's home kit, away team's away kit) have same color? Or it could also be other combinations? Let's read carefully: "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." So it says: if the two teams have the kits of the same color (i.e., the home team's home kit and the away team's away kit are the same color), then the away team switches to its home kit. That seems to be the only rule. But could there be a scenario where the away team's away kit color clashes with the home team's home kit? That's exactly it. So it's: For a game with home team i and away team j, normally: i wears xi, j wears yj. If xi == yj, then j instead wears xj (its home kit). That's it.
However, there could be another clash: what if after switching, the away team's home kit still clashes with home team's home kit? The problem statement doesn't mention any further adjustments. It just says if the kits are same color (presumably the kits that would be used: home's home and away's away), they cannot be distinguished, so the away team plays in its home kit. It doesn't say anything about checking if that new kit also clashes. Typically, the rule is that away team changes to home kit only if away's away kit collides with home's home. After that, it's okay if the home kit also collides? In football, both teams cannot wear the same color; it's to avoid confusion. So if after switching, they still share same color, would they still have issue? The problem statement says: "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." So they only consider the initial condition; after away team changes to home kit, presumably they are now distinguishable (maybe they could still be same color? but it's not handled). In typical Codeforces problem "Kit color" something like that, they usually only consider the immediate clash between home home and away away; after switching, they assume it's resolved even if both are home kits same color? Let's check examples:
Example 1:
n=2:
team1: home=1 away=2
team2: home=2 away=1
Games:
Home1 vs Away2: i=1 home, j=2 away. xi=1, yj=1? Wait y2 = away of team2 = 1? In input: team2: 2 1 => home=2, away=1. So for home1 vs away2: x1=1, y2=1 => equal -> away team (2) plays in its home kit = 2. So team2 wears 2, team1 wears 1 (distinguishable). So counts: team1 uses home kit in this game (home always uses home kit). team2 uses away? Actually it switched to home kit. So for team2, this game is "home" kit? It wears its home kit (color 2). That counts as playing in home kit? The output asks: number of games this team plays in home and away kits. So for team2, it played in home kit for that game, even though it's the away team. So we count accordingly.
Similarly, game home2 vs away1: x2=2, y1=2 => equal -> away team1 uses home kit=1. So team1 uses home kit, team2 uses home kit (team2 always home). So in that game, team1 uses home kit, team2 uses home kit.
Thus for team1: it has two games: as home (vs team2 away) where it wears home kit; as away (vs team2 home) where it wears home kit (due to clash). So total home kit games = 2, away kit games = 0. Output: "2 0" for both. So matches.
Now consider example 2:
n=3:
team1: 1 2
team2: 2 1
team3: 1 3
We need compute output:
3 1
4 0
2 2
Let's verify manually:
Teams:
T1: home=1, away=2
T2: home=2, away=1
T3: home=1, away=3
We have 6 games (since n(n-1)=3*2=6). Let's list:
Game1: Home T1 vs Away T2. x1=1, y2=1 => equal? y2=1, yes. So T2 (away) uses home kit: x2=2. So T1 uses home (1), T2 uses home (2). Count: T1 home, T2 home.
Game2: Home T1 vs Away T3. x1=1, y3=3 => different (1 vs 3). So T3 wears away kit=3. T1 home (1). So T1 home, T3 away.
Game3: Home T2 vs Away T1. x2=2, y1=2 => equal (2 vs 2). So T1 away uses home kit: x1=1. So T2 home (2), T1 home (1). So T2 home, T1 home.
Game4: Home T2 vs Away T3. x2=2, y3=3 => different (2 vs 3). So T3 away wears away=3. So T2 home, T3 away.
Game5: Home T3 vs Away T1. x3=1, y1=2 => different (1 vs 2). So T1 away wears away=2. So T3 home (1), T1 away (2). So T3 home, T1 away.
Game6: Home T3 vs Away T2. x3=1, y2=1 => equal (1 vs 1). So T2 away uses home kit: x2=2. So T3 home (1), T2 home (2). So T3 home, T2 home.
Now tally each team's home and away kit appearances:
Team1:
- Game1: home kit (since home)
- Game3: home kit (since away but switched)
- Game5: away kit (since away, no clash)
- Game2: home (home) actually we have: Game2: Home T1, so home kit. So include that.
Thus games for T1: as home: Game1, Game2 -> 2 home. as away: Game3 (home kit) counts as home, Game5 (away) counts as away. So total home kit: Game1, Game2, Game3 => 3 home. Away kit: Game5 => 1. Also check if T1 appears elsewhere: T1 only these 4 games? Actually each team plays 2*(n-1) = 4 games. Wait n=3, each team plays 2*(n-1) = 4 games: two home, two away. For T1: home vs T2 and T3, away vs T2 and T3. That's 4 games. We listed: Game1 (home vs T2), Game2 (home vs T3), Game3 (away vs T2), Game5 (away vs T3). So that's all. Home kit count = 3, away = 1. Output for team1 is 3 1. Good.
Team2:
Games: as home: vs T1 (Game1? Actually Game1: T1 home vs T2 away, that's T2 away; but T2 home games: vs T1 and vs T3. So Game3 is T2 home vs T1? Wait Game3: Home T2 vs Away T1. Yes Game3. Game4: Home T2 vs Away T3. So T2 home games: Game3 and Game4. As away: vs T1 (Game1) and vs T3 (Game6). So let's tally:
- Game3 (home): T2 wears home kit (2)
- Game4 (home): T2 wears home kit (2)
- Game1 (away): T2 away vs T1: we had clash -> T2 wore home kit (2)
- Game6 (away): T2 away vs T3: clash (x3=1, y2=1) -> T2 wore home kit (2)
Thus T2 wears home kit in all 4 games: home kit count = 4, away = 0. Output says 4 0. Good.
Team3:
Games: home vs T1 (Game5), home vs T2 (Game6). away vs T1 (Game2), away vs T2 (Game4). Tally:
- Game5 (home): T3 wears home kit (1)
- Game6 (home): T3 wears home kit (1)
- Game2 (away): T3 away vs T1: no clash (x1=1, y3=3 different) -> T3 wears away kit (3)
- Game4 (away): T3 away vs T2: no clash (x2=2, y3=3 different) -> T3 wears away kit (3)
Thus T3 home kit count = 2, away count = 2. Output says 2 2. Good.
So the interpretation is correct: for each game between i (home) and j (away), if xi == yj, then j uses xj (home kit) instead of yj. No further checking.
Thus for each team i, we need to compute:
- Number of games where team i is home: all its home games count as home kit. That's n-1 games (since one home game against each other team).
- Number of games where team i is away: normally it would wear away kit, except when the home team's home color equals its away color. In those cases, i wears its home kit.
So let:
home_games_i = n-1 (always in home kit)
away_games_i = n-1 (as many away games). Among those, some are in away kit, some in home kit (due to clash). So we need to count for team i, how many times when it plays away (against some home team j) we have xi? Actually condition: For team i being away against home team j, the clash condition is: xj == yi (home team's home color equals away team's away color). If true, then i wears its home kit (xi). If false, i wears away kit (yi). So we need to count for each team i: number of j (j != i) such that xj == yi. That's the number of away games where i will wear home kit (due to clash). Then the remaining away games, i wears away kit.
Thus total home kit appearances for i = (n-1) + (count of j != i with xj == yi)
total away kit appearances for i = (n-1) - (count of j != i with xj == yi)
But careful: is there any situation where team i as away wears home kit due to something else? The rule only triggers if xj == yi. So yes.
Thus the answer for each team is: home = n-1 + c_i, away = n-1 - c_i, where c_i = number of teams j (j != i) such that xj == yi.
Check with examples:
Example1: n=2, teams: (x1=1, y1=2), (x2=2, y2=1)
For team1: yi=2. Count of j !=1 with xj == 2? x2=2 => count=1. So home = 1 + 1 = 2, away = 1 - 1 =0. OK.
team2: yi=1. Count of j !=2 with xj==1? x1=1 => count=1. home=1+1=2, away=1-1=0. OK.
Example2: n=3, team1: y1=2. Count of j !=1 with xj == 2? x2=2 => count=1. home = 2+1=3, away=2-1=1. OK.
team2: y2=1. Count of j !=2 with xj==1? x1=1 and x3=1 => count=2. home=2+2=4, away=2-2=0. OK.
team3: y3=3. Count of j !=3 with xj==3? none (x1=1, x2=2) => 0. home=2+0=2, away=2-0=2. OK.
Thus the solution reduces to computing for each team i, the count c_i = frequency of the value yi among the x colors of other teams (excluding i itself). Since n up to 1e5, straightforward O(n^2) is too slow. We can compute total frequency of each color among all x's, then for each i, c_i = freq_x[yi] - (1 if xi == yi else 0)? Actually we must exclude team i itself: if team i's own x color equals yi, then that would count if we include all teams. So c_i = total_freq_x[yi] - (1 if xi == yi else 0). Because only teams j != i. And note that xi and yi are distinct for each team? Input says xi != yi, so xi != yi always. So we can safely say c_i = total_freq_x[yi] because team i cannot have xi == yi (since they are different). Therefore no need to subtract self. However, careful: the condition j != i, but since xi != yi, even if we include i, it wouldn't contribute because we need xj == yi, and xi != yi, so including i adds 0. So we can just use total_freq_x[yi] as c_i. But wait, what about the case where there is another team with same x and y? Not possible because xi != yi. So indeed self does not count. So c_i = count of all teams (including i?) such that xj == yi. Since for i itself, xi != yi, so no contribution. Thus c_i = freq_x[yi].
But careful: Are there any constraints? The condition for away team's kit change only applies when playing away. In a game where i is away and j is home, if xj == yi, then i wears home kit. But note that if j's home color equals yi, it's possible that j's away color also equals something, but doesn't matter. So indeed, we need number of j's such that xj == yi. And j can be any team except i, but since xi != yi, we don't accidentally count i. So c_i = freq_x[yi].
Thus answer: home_i = (n-1) + freq_x[yi]; away_i = (n-1) - freq_x[yi].
But is that correct? Let's test with more scenarios, maybe potential edge cases where multiple teams share same colors.
Consider n=3: (1,2), (1,3), (2,3). So team1: x=1,y=2; team2: x=1,y=3; team3: x=2,y=3.
Compute freq_x: color1:2, color2:1, color3:0.
c1 = freq_x[y1=2] =1; home=2+1=3, away=2-1=1.
c2 = freq_x[y2=3] =0; home=2, away=2.
c3 = freq_x[y3=3] =0; home=2, away=2.
Now simulate manually? Let's list games:
Team1 home vs Team2 away: x1=1, y2=3 (different) => team2 away kit 3; team1 home.
Home1 vs Away3: x1=1, y3=3 (different) => team3 away 3; team1 home.
Home2 vs Away1: x2=1, y1=2 (different) => team1 away 2; team2 home.
Home2 vs Away3: x2=1, y3=3 (different) => team3 away 3; team2 home.
Home3 vs Away1: x3=2, y1=2 (equal) => team1 away uses home x1=1; team3 home.
Home3 vs Away2: x3=2, y2=3 (different) => team2 away 3; team3 home.
Now tally:
Team1: home games (2) => home kit in both. Away games: vs team2 home (wore away 2) -> away; vs team3 home (wore home) -> home. So home total=3, away=1. matches.
Team2: home games (2) => home kit. Away games: vs team1 home (wore away 3) -> away; vs team3 home (wore away 3) -> away. So home=2, away=2. matches.
Team3: home games (2) => home kit. Away games: vs team1 home (wore away 3) -> away; vs team2 home (wore away 3) -> away. So home=2, away=2. matches. Good.
Now test scenario where many teams have same x. For instance, n=4: all teams have x=1, but each has distinct y's (and xi != yi so y's !=1). Then freq_x[1]=4. For each team i, c_i = freq_x[yi] but yi's are not 1, so likely 0. So home_i = 3, away_i = 3. Let's manually reason: For any away game, the home team has x=1. The away team's away color yi is not 1, so no clash. So each away game, away team wears away. So home kit uses: 3 home games; away kit: 3 away games. That sums 6 games per team? Actually each team plays 6 games total: 3 home, 3 away. So home kit =3, away=3. Good.
Now scenario where some teams have y equal to some x. For example, n=4: team1: x=1,y=2; team2: x=2,y=3; team3: x=3,y=1; team4: x=4,y=5. freq_x: 1:1,2:1,3:1,4:1,5:0. c1=freq_x[2]=1; home=3+1=4, away=2; c2=freq_x[3]=1; home=4, away=2; c3=freq_x[1]=1; home=4, away=2; c4=freq_x[5]=0; home=3, away=3. So each of first three teams have one extra home kit game due to clash. Let's manually check for team1: Away games vs home teams with x==2? That's team2 (x=2). So away vs team2: clash (x2=2, y1=2) -> team1 wears home. So team1 wears home in that away game. The other two away games (vs team3, team4) no clash because x3=3, x4=4, y1=2, no match. So home kit total = home games (3) + 1 =4; away kit total = 3-1=2. Good.
Thus solution seems straightforward: compute frequency map of x colors. For each team, output home = n-1 + freq_x[yi], away = n-1 - freq_x[yi].
But wait, is there any nuance about the case when the away team's away kit equals the home team's home kit and then away team switches to its home kit; but what if that home kit also equals the home team's home kit? That would be another clash, but the problem does not mention handling that. In the examples, we saw that after switching, they could still be same color? Let's test possible scenario: team A: home=1, away=2; team B: home=1, away=3? But xi != yi so each team's colors are distinct. Could we have xA = 1, yB = 1? That would be clash. Then B away would wear home kit, which is xB. xB could also be 1? But then xB must be distinct from yB (since xi != yi). If yB = 1, then xB != 1. So xB is not 1. So after switching, the away team's home kit (xB) is not equal to 1 (unless xB=1 which is impossible because it must differ from yB=1). So no double clash. Another scenario: team A: home=1, away=2; team B: home=2, away=1. Then when A home vs B away: xA=1, yB=1 -> clash -> B wears xB=2, distinct. When B home vs A away: xB=2, yA=2 -> clash -> A wears xA=1, distinct. So still distinct.
But what about if team A: home=1, away=2; team B: home=2, away=3; then clash when A home vs B away? xA=1, yB=3, no clash. When B home vs A away: xB=2, yA=2 clash, then A wears xA=1, distinct. So fine.
The only potential for double clash would be if there existed a team with home kit equal to its away kit? But that's not allowed. Or if after switching, the away team's home kit equals the home team's home kit. Could that happen? Suppose xA = 1, yB = 1 (clash). Then B switches to xB. Could xB be 1? But yB=1 and xi != yi for B, so xB != 1. So cannot. So after switching, colors are distinct. So problem's ignoring double clash is fine.
Thus solution is simple.
But wait, the problem statement: "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." It says "if two teams has the kits of the same color", which might refer to the kits they would be wearing: home team's home kit and away team's away kit. So yes.
Thus answer: For each team i, home games count = n-1, away games count = n-1. Among away games, number where it wears home kit = count of teams j such that xj == yi. So final counts as above.
Implementation: read n, arrays x[1..n], y[1..n]. Compute frequency of x values: using a dictionary (or array of size up to 1e5? Actually colors up to 1e5, but constraints say 1 ≤ xi, yi ≤ 10^5. So we can allocate array of size 100001 or use dict. Since n up to 1e5, using array of size 200000 maybe fine. We'll use defaultdict(int) or list. But be careful: colors go up to 100000, but maybe 10^5? Input says 1 ≤ xi, yi ≤ 10^5. So array of size 100001 (or 200001 for safety) works.
We'll store freq[color] = number of teams with that x.
Then for each i, compute c = freq[y[i]], output (n-1 + c, n-1 - c).
Edge case: Could y[i] be > max? Not. So fine.
But we need to ensure we handle 64-bit integers? n up to 1e5, so n-1 up to 99999. freq up to n=100000. So home_i up to (n-1) + n = about 200000. This fits within 32-bit int (max ~2e9). But safe to use 64-bit.
Now, is there any other nuance? The problem says "each team plays exactly one home game and exactly one away game with each other team". So yes, each team has n-1 home games and n-1 away games. So base counts as above.
But wait, is there any scenario where a team i, when playing away, might also be forced to wear home kit because of some other reason? For instance, if the away team's away kit color equals the home team's away kit? But that's not considered. Only clash between home's home and away's away. So fine.
Thus solution straightforward.
But hold on: In the problem, the away team plays in its away kit normally. If they have same color, the away team plays in its home kit. So it's just as we used.
Now we should double-check with the examples given. Already matches.
Thus answer is simple.
But is there any catch? Could there be a case where the home team's home color equals the away team's home color? That would be both in home kits if away team had to switch. But that situation does not trigger a switch. So no.
Thus we can implement.
But wait: Could there be a scenario where both conditions? Actually, the rule is: "if two teams has the kits of the same color, they cannot be distinguished." Possibly they refer to the kits that the two teams would wear: home's home and away's away. Yes.
Thus solution stands.
Now confirm with another random test with many same colors. For instance, n=5:
Team1: (1,2)
Team2: (1,3)
Team3: (2,4)
Team4: (2,5)
Team5: (3,6)
Compute freq_x: 1:2, 2:2, 3:1, others 0.
For team1: y=2 -> freq_x[2]=2 -> home=4+2=6, away=4-2=2.
team2: y=3 -> freq_x[3]=1 -> home=5, away=3.
team3: y=4 -> freq_x[4]=0 -> home=4, away=4.
team4: y=5 -> 0 -> home=4, away=4.
team5: y=6 -> 0 -> home=4, away=4.
Now simulate mentally a few: Away games for team1: opponents home x values: team2 x=1, team3 x=2, team4 x=2, team5 x=3. Among these, which have x == y1=2? team3 and team4 (both x=2). So team1 will wear home kit in those two away games. Others (team2 and team5) wear away. So home kit total = 4 home + 2 =6, away = 2. Good.
Thus algorithm works.
Now complexity: O(n) time, O(max_color) memory (or O(distinct colors) using map).
Implementation steps:
- Read n.
- Initialize freq array of size maybe 200001 (since colors up to 100000) or use dict.
- Loop i from 0 to n-1:
read x_i, y_i.
store in arrays (or just store y_i; we need later).
increment freq[x_i].
- Then loop i from 0 to n-1:
c = freq[y_i]
home = (n-1) + c
away = (n-1) - c
print home, away
Edge Cases:
- If y_i is large, we need freq array size enough. Use dict to be safe, or compute max color from input. But given constraints, 100000 is fine; allocate maybe size 200001 to be safe.
- But note: colors may be up to 10^5, array index up to 10^5 works (0 to 100000 inclusive). Use list of length 100001? but careful: if color exactly 100000, need index 100000, so length at least 100001 (since 0-index). So allocate [0] * (100001) or bigger.
But there's also possibility that colors may exceed 100000? The constraints say 1 ≤ xi, yi ≤ 10^5, so max 100000. So array size 100001 is fine.
Alternatively, could use collections.Counter.
Implementation in Python:
def solve():
import sys
input = sys.stdin.readline
n = int(input())
x = [0]*n
y = [0]n
max_c = 100000
freq = [0](max_c+1)
for i in range(n):
xi, yi = map(int, input().split())
x[i] = xi
y[i] = yi
freq[xi] += 1
base = n-1
out_lines = []
for i in range(n):
c = freq[y[i]]
home = base + c
away = base - c
out_lines.append(f"{home} {away}")
sys.stdout.write("\n".join(out_lines))
Check: In sample, works.
But wait: Is there any scenario where the away team's away kit color equals the home team's home color but also the away team's home kit is the same as the home team's home color? Not possible as argued. But what if the away team's home kit equals the home team's home color? That would happen if xi == xj? Could that cause any extra rule? The problem statement doesn't mention anything about that. In real football, if both wear same colored kits, one changes. Here only away team changes if there's a clash with away kit. So if after change both are same, the problem doesn't say to resolve further. However, as argued, due to xi != yi, after switching, away team's home kit cannot equal home team's home kit when the clash condition triggered? Let's prove: The condition triggering is xj == yi (home's home = away's away). After switching, away wears xi. Could xi equal xj? Possibly, if xi == xj. That's not prevented. For example: Team i (away) has home=1, away=2. Team j (home) has home=2, away=1? Wait, home's home = 2, away's away=2? Actually condition: xj == yi. Suppose j's home = 2, i's away = 2. Then i's home = xi (1). So xi = 1, xj = 2, not equal. But can we have xi == xj while still xj == yi? Since yi != xi, if xj == yi, then xj == yi != xi, so xj != xi. So after switch, away's home kit (xi) is different from home's home kit (xj). Because xj == yi and yi != xi, so xj != xi. So indeed they are distinct. Thus after switching, they are always different colors. Good.
But what about the case when there is no clash? Then away wears yi. Could yi equal xj? That would be the clash condition, so it would be caught. So either clash or not. So final kits are always distinguishable.
Thus answer stands.
Now let's consider if the problem expects us to consider that the away team might also need to change if its away kit matches the home team's away kit? The statement says "if two teams has the kits of the same color, they cannot be distinguished." It doesn't specify which kits. In typical football, the two kits are the ones the teams are wearing. So the condition should check the colors of the kits being worn. Initially, the kits being worn would be home's home and away's away. If they clash, away changes to its home kit. So final kits are then compared? Actually the condition "if two teams has the kits of the same color" might refer to the kits they would be wearing after applying the rule? But the rule is applied only if they have same color. It seems like: Initially, home wears home, away wears away. If those two are same color, then they cannot be distinguished, so the away team plays in its home kit. It doesn't say to check again. So it's exactly as we used.
Thus solution is final.
Given the simplicity, we can directly output.
But I recall a Codeforces problem: "Kitayuta, the ..."? Actually it's "Kitayuta's Colorful Graph"? No. Maybe it's "Football Kit" from Codeforces Round 124? Something like that. Indeed this is a well-known easy problem. The solution is as described.
Now, one more thing: we must handle large n efficiently and output correctly.
Hence final solution.
But before finalizing, double-check if there's any hidden condition about the away team also switching when its away kit matches the home team's away kit? Or perhaps the rule is: "If the kits of the two teams have the same color, the away team plays in its home kit." This could be interpreted as: after assigning kits (home wears home, away wears away), if those two kits have the same color, then away changes to home. That's what we did. So okay.
Now, there's another nuance: The problem says "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." It doesn't specify that the away team's away kit is the one considered; it says "two teams has the kits of the same color" - meaning the two kits they are wearing. So it's consistent.
Thus answer is correct.
Edge Cases:
- n=2, already tested.
- n=100000, all colors distinct, then freq_x[yi] = 0 for all (since yi are distinct and also not equal to any x? Could be if yi equals some xj, but since colors distinct, maybe not). Then answer for all: home = n-1, away = n-1.
- If many teams share same x, but yi may also equal that x? But yi != xi, but can equal other team's x. So fine.
Implementation details: We'll read input, store y's for each team, compute freq of x.
Complexities: O(n + range of colors) time, O(range) memory.
Potential memory: 100001 integers, fine.
Thus final.
But the problem might have constraints where xi, yi can be up to 10^9? Actually problem statement says 1 ≤ xi, yi ≤ 10^5. So safe.
Now, a final thought: Could there be scenario where the away team's away kit equals the home team's away kit? That would not cause a change because the away team is wearing away and home team is wearing home; home's away kit is not used. So irrelevant.
Hence answer.
Now let's craft the final solution description.
We'll write in Python:
import sys
def main():
data = sys.stdin.read().strip().split()
if not data: return
it = iter(data)
n = int(next(it))
x = [0]*n
y = [0]n
max_color = 100000
freq = [0](max_color+1)
for i in range(n):
xi = int(next(it)); yi = int(next(it))
x[i] = xi; y[i] = yi
freq[xi] += 1
base = n-1
out = []
for i in range(n):
c = freq[y[i]]
home = base + c
away = base - c
out.append(f"{home} {away}")
sys.stdout.write("\n".join(out))
if name == "main":
main()
Check with examples.
Thus final answer. ```python
import sys
def main():
data = sys.stdin.buffer.read().split()
if not data:
return
it = iter(data)
n = int(next(it))
# We only need to store y values, but also need to read x to count frequencies.
y = [0] * n
# Maximum possible colour is 100000 according to constraints.
MAX_COLOR = 100000
freq_x = [0] * (MAX_COLOR + 1)
for i in range(n):
xi = int(next(it))
yi = int(next(it))
y[i] = yi
freq_x[xi] += 1
base = n - 1 # number of home games = number of away games
out_lines = []
for i in range(n):
c = freq_x[y[i]] # number of opponents whose home kit colour equals this team's away colour
home = base + c
away = base - c
out_lines.append(f"{home} {away}")
sys.stdout.write("\n".join(out_lines))
if name == "main":
main()