CodeCoder vs TopForces

Each citizen reaches another through a chain of pairwise wins on at least one of two rating sites; count reachable citizens from each node.

Medium7GraphSortingDFSUnion-findNo attempts yetTime limit2sMemory limit256 MB

Problem

Competitive programming is popular in Byteland. Every citizen of Byteland is registered on two judge sites, CodeCoder and TopForces. Each site runs its own rating system. On each site every citizen has one integer rating that estimates their skill, and no two citizens share a rating on the same site. A higher rating means a better skill.

Citizens of Byteland are optimistic. Citizen AA thinks they have a chance to beat citizen BB in a contest if there is a sequence of citizens A=P0,P1,,Pk=BA = P_0, P_1, \ldots, P_k = B with k1k \ge 1 such that for every ii with 0i<k0 \le i < k, citizen PiP_i has a higher rating than Pi+1P_{i+1} on at least one of the two sites.

For every citizen, find how many citizens other than themselves they think they have a chance to beat.

Input

The first line contains an integer nn, the number of citizens (1n1000001 \le n \le 100\,000).

The ii-th of the next nn lines contains two integers CCiCC_i and TFiTF_i, the rating of citizen ii on CodeCoder and on TopForces (1CCi,TFi1061 \le CC_i, TF_i \le 10^6). On each site the nn ratings are pairwise distinct.

Output

Print nn lines. The ii-th line contains bib_i, the number of citizens other than citizen ii that citizen ii thinks they have a chance to beat. Print the answers in the input order.