P1702 Surprise Exam

Description

One day, the teacher decides to hold a surprise exam. It is known that each student has an ability level. There are $N$ desks in the classroom, arranged in a single row. Each desk can seat two students; the two students at desk $i$ have ability levels $A_i$ and $B_i$. The teacher now decides to test people whose ability level is $K$. He will choose $L$ consecutive desks from these $N$ desks for the exam, requiring that each of these $L$ desks has at least one person whose ability level is $K$. We want to determine the maximum possible $L$ and the corresponding $K$.

Input Format

Line 1: an integer $N$. Lines 2 to $N+1$: each line contains two integers, $A_i$ and $B_i$.

Output Format

Output two integers $L$ and $K$, where $L$ is maximized; among those, choose the smallest possible $K$.

Explanation/Hint

### Constraints For all testdata, $1 \le N \le 100{,}000$, $1 \le A_i, B_i \le 5$. Translated by ChatGPT 5