PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#CC0000057. So sánh xếp hạng lập trình viên (Coder Ratings)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

So sánh xếp hạng lập trình viên (Coder Ratings)

Coder Ratings

Source: SPOJ

Version: Phuoc Hung OJ Extended

Problem Statement

Each coder has an Open rating AiA_i and a High School rating HiH_i. Coder ii is better than coder jj if Ai≥AjA_i\ge A_j and Hi≥HjH_i\ge H_j, with at least one inequality strict. Count how many coders each coder is better than.

Input

The first line is nn, followed by nn pairs of ratings Ai,HiA_i,H_i.

Output

Print nn lines with the number of coders each original coder is better than.

Subtasks

  • Subtask 1 (20 points): 1≤n≤201\le n\le20; 1≤Ai,Hi≤1000001\le A_i,H_i\le100000.
  • Subtask 2 (30 points): 1≤n≤15001\le n\le1500; 1≤Ai,Hi≤1000001\le A_i,H_i\le100000.
  • Subtask 3 (50 points): 1≤n≤3000001\le n\le300000; 1≤Ai,Hi≤1000001\le A_i,H_i\le100000.

Examples

Input

8
1798 1832
862 700
1075 1089
1568 1557
2575 1984
1033 950
1656 1649
1014 1473

Output

6
0
2
4
7
1
5
1

Explanation

Coder 5 dominates all seven other coders; coder 2 dominates none. Identical rating pairs never dominate each other under the required strictness.