#abc348c. C - Colorful Beans

C - Colorful Beans

Score: 250250 points

问题陈述

NN 种类型的豆子,每种类型一个豆子。第 ii 种类型的豆子美味度为 AiA_i,颜色为 CiC_i。豆子被混合在一起,只能通过颜色来区分。

你将选择一种颜色的豆子并吃下一个该颜色的豆子。通过选择最优颜色,最大化你所吃豆子的最小可能美味度。

以上为大语言模型 kimi 翻译,仅供参考。

Problem Statement

There are NN types of beans, one bean of each type. The ii-th type of bean has a deliciousness of AiA_i and a color of CiC_i. The beans are mixed and can only be distinguished by color.

You will choose one color of beans and eat one bean of that color. By selecting the optimal color, maximize the minimum possible deliciousness of the bean you eat.

Constraints

  • 1N2×1051 \leq N \leq 2 \times 10^{5}
  • 1Ai1091 \leq A_i \leq 10^{9}
  • 1Ci1091 \leq C_i \leq 10^{9}
  • All input values are integers.

Input

The input is given from Standard Input in the following format:

NN

A1A_1 C1C_1

A2A_2 C2C_2

\vdots

ANA_N CNC_N

Output

Print as an integer the maximum value of the minimum possible deliciousness of the bean you eat.

Sample Input 1

4
100 1
20 5
30 5
40 1

Sample Output 1

40

Note that beans of the same color cannot be distinguished from each other.

You can choose color 11 or color 55.

  • There are two types of beans of color 11, with deliciousness of 100100 and 4040. Thus, the minimum deliciousness when choosing color 11 is 4040.
  • There are two types of beans of color 55, with deliciousness of 2020 and 3030. Thus, the minimum deliciousness when choosing color 55 is 2020.

To maximize the minimum deliciousness, you should choose color 11, so print the minimum deliciousness in that case: 4040.

Sample Input 2

10
68 3
17 2
99 2
92 4
82 4
10 3
100 2
78 1
3 1
35 4

Sample Output 2

35