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

#CC0000054. Đếm các đoạn nằm bên trong (Nested Segments)

HỌC THEO LỘ TRÌNH

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

2 lộ trình

Đếm các đoạn nằm bên trong (Nested Segments)

Nested Segments

Source: Codeforces

Version: Phuoc Hung OJ Extended

Problem Statement

There are nn segments whose 2n2n endpoints are all distinct. For each segment ii, count other segments entirely inside it, so li<ljl_i<l_j and rj<rir_j<r_i.

Input

The first line contains nn, followed by nn lines of endpoints li,ril_i,r_i.

Output

Print nn lines: the count of other segments inside each original segment.

Subtasks

  • Subtask 1 (20 points): 1≤n≤201\le n\le20; −109≤li<ri≤109-10^9\le l_i<r_i\le10^9; all 2n2n endpoints are distinct.
  • Subtask 2 (30 points): 1≤n≤15001\le n\le1500; −109≤li<ri≤109-10^9\le l_i<r_i\le10^9; all 2n2n endpoints are distinct.
  • Subtask 3 (50 points): 1≤n≤2000001\le n\le200000; −109≤li<ri≤109-10^9\le l_i<r_i\le10^9; all 2n2n endpoints are distinct.

Examples

Input

4
1 8
2 3
4 7
5 6

Output

3
0
1
0

Explanation

The segment [1,8] contains all three others; [4,7] contains [5,6]. The remaining two contain none.