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 A thinks they have a chance to beat citizen B in a contest if there is a sequence of citizens A=P0,P1,…,Pk=B with k≥1 such that for every i with 0≤i<k, citizen Pi has a higher rating than Pi+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.