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

#PS0000269. Đoạn có mức phủ lớn nhất (Maximum Coverage Duration)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Đoạn có mức phủ lớn nhất (Maximum Coverage Duration)

Maximum Coverage Duration

Source: Phước Hưng OJ

Version: Phuoc Hung OJ Extended

Problem Statement

Given NN half-open intervals [li,ri)[l_i,r_i), the coverage at a point is the number of intervals containing it, counting duplicates separately. Find the maximum coverage CC and the total length of all regions with coverage exactly CC. The length of [a,b)[a,b) is b−ab-a, not the number of endpoints.

Input

First line: NN. Next NN lines: li,ril_i,r_i.

Output

Print two integers C,TC,T on one line: maximum coverage and total length attaining it.

Subtasks

  • Subtask 1 (20 points): 1≤N≤1001\le N\le 100; 0≤li<ri≤1000\le l_i<r_i\le 100.
  • Subtask 2 (30 points): 1≤N≤2000001\le N\le 200000; 0≤li<ri≤10120\le l_i<r_i\le 10^12; li=l1l_i=l_1.
  • Subtask 3 (50 points): 1≤N≤2000001\le N\le 200000; 0≤li<ri≤10120\le l_i<r_i\le 10^12.

Example 1

Input

4
0 4
2 5
8 10
9 12

Output

2 3

Explanation

Coverage 2 occurs on [2,4) and [9,10), total length 3.

Example 2

Input

2
1 3
3 5

Output

1 4

Explanation

The intervals touch without overlapping; maximum coverage 1 lasts 4 units.