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

#CC0000055. Đếm quan hệ bao nhau giữa các đoạn (Nested Ranges Count)

HỌC THEO LỘ TRÌNH

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

2 lộ trình

Đếm quan hệ bao nhau giữa các đoạn (Nested Ranges Count)

Nested Ranges Count

Source: CSES

Version: Phuoc Hung OJ Extended

Problem Statement

You are given nn distinct inclusive ranges. Range [a,b][a,b] contains [c,d][c,d] if a≤ca\le c and d≤bd\le b. For each range, count the other ranges it contains and those that contain it, preserving input order.

Input

The first line is nn, followed by nn inclusive ranges [xi,yi][x_i,y_i].

Output

Print nn contained-range counts, followed by nn containing-range counts.

Subtasks

  • Subtask 1 (20 points): 1≤n≤201\le n\le20; 1≤xi<yi≤1091\le x_i<y_i\le10^9; no two ranges are identical.
  • Subtask 2 (30 points): 1≤n≤15001\le n\le1500; 1≤xi<yi≤1091\le x_i<y_i\le10^9; no two ranges are identical.
  • Subtask 3 (50 points): 1≤n≤2000001\le n\le200000; 1≤xi<yi≤1091\le x_i<y_i\le10^9; no two ranges are identical.

Examples

Input

4
1 6
2 4
4 8
3 6

Output

2 0 0 0
0 1 0 1

Explanation

[1,6] contains [2,4] and [3,6]; those two ranges are each contained once, while [4,8] participates in no containment relation.