P6444 [COCI 2010/2011 #1] PROFESOR

Description

In a long classroom, there are $n$ desks in a single row, and each desk has $2$ students sitting at it. The students are daydreaming because they are about to have an art class, and their professor is planning to test them. Each student has learned art, but only up to a certain level. The professor can tell how much they have learned by the look on their faces. The professor is an artist, and each grade uses colored pencils of different colors. Unfortunately, today he brought only $1$ pencil. To make the test seem fair, he wants to choose $2$ desks, and ask $1$ student from every desk between the two chosen desks (including the chosen desks). It is important that all tested students receive the same grade, so that he can write it down with the single pencil. The professor wants to know the maximum number of students he can test in this way, and what grade the students will receive.

Input Format

The input has $n + 1$ lines. The first line contains an integer $n$, as described above. The next $n$ lines each contain two integers: $a_i$ and $b_i$, which are the grades of the students sitting at desk $i$.

Output Format

Output one line. Print $2$ numbers separated by a single space: the maximum number of students the professor can test, and the grade those students will receive. If there are multiple solutions, output the one with the smallest grade.

Explanation/Hint

#### Constraints For $100\%$ of the testdata, $1 \le n \le 10^5$, $1 \le a_i, b_i \leq 5$. #### Notes **Translated from [COCI2010-2011](https://hsin.hr/coci/archive/2010_2011/) [CONTEST #1](https://hsin.hr/coci/archive/2010_2011/contest1_tasks.pdf) *T2 PROFESOR*.** Translated by ChatGPT 5