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

#PS0000261. Năm có dân số lớn nhất (Maximum Population Year)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Năm có dân số lớn nhất (Maximum Population Year)

Maximum Population Year

Source: LeetCode

Version: Phuoc Hung OJ Extended

Problem Statement

Each of NN people contributes to the population in years bib_i through di−1d_i-1, excluding the death year did_i. Find the earliest year attaining maximum population.

Input

First line: NN. Next NN lines: bi,dib_i,d_i.

Output

Print the earliest year with maximum population.

Subtasks

  • Subtask 1 (20 points): 1≤N≤51\le N\le 5; 1950≤bi<di≤20501950\le b_i<d_i\le2050.
  • Subtask 2 (30 points): 1≤N≤1001\le N\le 100; 1950≤bi<di≤20501950\le b_i<d_i\le2050; bi=b1b_i=b_1.
  • Subtask 3 (50 points): 1≤N≤1001\le N\le 100; 1950≤bi<di≤20501950\le b_i<d_i\le2050.

Example 1

Input

2
1993 1999
2000 2010

Output

1993

Explanation

No overlapping lifespans; 1993 is the first year with population 1.

Example 2

Input

3
1950 1961
1960 1971
1970 1981

Output

1960

Explanation

Population is 2 in 1960 and 1970; choose 1960.