eolymp
bolt
Try our new interface for solving problems

Jams

\includegraphics{https://static.e-olymp.com/content/a0/a01d6fe5baf86fd274dfc5600a30f76cc672dd3c.jpg} Boondex has decided to improve its traffic jams coloring algorithm to be more consistent with drivers' expectations. For this purpose Boondex has collected drivers' feedback as a set of \textbf{N} integer pairs \textbf{V_i}, \textbf{C_i} where \textbf{V_i} is the speed of the driver's vehicle and \textbf{C_i} (\textbf{C_i} \{\textbf{0}, \textbf{1}, \textbf{2}\}) is the color that is expected to be seen on the map for this speed by this driver. Please help Boondex find two integers \textbf{A} and \textbf{B} (\textbf{0} ≤ \textbf{A} ≤ \textbf{B}) that will be used for their new traffic jams coloring algorithm. Traffic color will be considered to be color \textbf{0} if \textbf{0} ≤ \textbf{V} ≤ \textbf{A}, color \textbf{1} if \textbf{(A+1)} ≤ \textbf{V} ≤ \textbf{B} and color \textbf{2} if \textbf{(B+1)} ≤ \textbf{V}. Values \textbf{A} and \textbf{B} should be chosen to minimize the number of cases where traffic color from the new coloring algorithm is different from the driver's feedback. Among the possible combinations of \textbf{A} and \textbf{B} minimizing the number of such cases, the one with minimal value of \textbf{(A+B)} should be chosen as an answer. \InputFile \includegraphics{https://static.e-olymp.com/content/a0/a01d6fe5baf86fd274dfc5600a30f76cc672dd3c.jpg} In the first line of input integer \textbf{N} is given - the total number of feedback pairs (\textbf{1} ≤ \textbf{N} ≤ \textbf{10^5}). On the next \textbf{N} lines of input integers \textbf{V_i} (\textbf{0} ≤ \textbf{V_i} ≤ \textbf{10^6}) and \textbf{C_i} (\textbf{Ci} \{\textbf{0}, \textbf{1}, \textbf{2}\}) are given - the driver's speed and expected trac color for that speed respectively. \OutputFile Print two integers \textbf{A} and \textbf{B} - the answer for this problem.
Time limit 1 second
Memory limit 256 MiB
Input example #1
3
5 0
20 1
40 2
Output example #1
5 20