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

#CC0000050. Kiểm tra các đoạn bao nhau (Nested Ranges Check)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Kiểm tra các đoạn bao nhau (Nested Ranges Check)

Nested Ranges Check

Source: CSES

Version: Phuoc Hung OJ Extended

Problem Statement

You are given nn inclusive ranges. A range [a,b][a,b] contains [c,d][c,d] if a≤ca\le c and d≤bd\le b. For every original range, decide whether it contains another range and whether it is contained in another range. Report both arrays in input order.

Input

The first line is nn. Each of the following nn lines contains the closed interval endpoints xi,yix_i,y_i.

Output

Print nn binary flags for ranges containing another range, then nn flags for ranges contained in another range.

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

1 0 0 0
0 1 0 1

Explanation

The range [1,6][1,6] contains [2,4][2,4] and [3,6][3,6]. Only the first range contains another; the second and fourth are contained.