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

#GD0000092. Phản ví dụ: chọn đoạn ngắn nhất (Shortest Interval Counterexample)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Phản ví dụ: chọn đoạn ngắn nhất (Shortest Interval Counterexample)

Shortest Interval Counterexample

Source: Phước Hưng OJ

Version: Phuoc Hung OJ Extended

Problem Statement

Given nn half-open jobs [li,ri)[l_i,r_i), no two overlapping jobs can both be chosen. Strategy A repeatedly chooses the remaining shortest-duration job, breaking ties by smaller start and then smaller original index, and eliminates every job overlapping it. Strategy B chooses the maximum possible number of compatible jobs. Output both counts. Touching at endpoints does not count as overlap.

Input

The first line contains nn. The next nn lines contain li,ril_i,r_i for job ii.

Output

Print two integers: the number chosen by strategy A and the maximum number chosen by strategy B.

Subtasks

  • Subtask 1 (20 points): 1≤n≤61\le n\le6; 0≤li<ri≤1050\le l_i<r_i\le10^5.
  • Subtask 2 (30 points): 1≤n≤101\le n\le10; 0≤li<ri≤1050\le l_i<r_i\le10^5.
  • Subtask 3 (50 points): 1≤n≤181\le n\le18; 0≤li<ri≤1050\le l_i<r_i\le10^5.

Examples

Input

3
0 3
2 4
3 6

Output

1 2

Explanation

Durations are 3,2,33,2,3. Strategy A first picks [2,4)[2,4), which overlaps both others, yielding only 11 job. Strategy B picks [0,3)[0,3) and [3,6)[3,6), which meet at an endpoint, so the optimum is 22.