Lost Island

아직 제출이 없습니다시간 제한2초메모리 제한512 MB

문제

There is an island far away occupied by a tribe. Among people in this tribe, nn eye colors occur: there are a_ia\_i people with the eye color ii (a_i>0a\_i > 0), and there are no other colors known to the tribe. More formally, the members of the tribe know the value of nn, but they don't know that all eye colors actually occur (that all a_i>0a\_i > 0). The tribe follows a specific religion: if someone can deduce their own eye color, they commit suicide the next day. It must be said, the people in the tribe are incredibly smart.

Once, at day 0, a traveler arrives to the island, meets the tribe and says nn true sentences, in which b_i0b\_i \ge 0, and at least one b_i>0b\_i > 0:

  • Wow, there are at least b_1b\_1 people among you with the eye color 11!
  • Wow, there are at least b_2b\_2 people among you with the eye color 22!
  • ...
  • Wow, there are at least b_nb\_n people among you with the eye color nn!

Find the last day when the suicides will take place and the total number of people committed suicide.

입력

The first line contains an integer nn (2n2000002 \le n \le 200000) --- the number of eye colors.

Each of the next nn lines contains two integers a_ia\_i and b_ib\_i (1a_i109,0b_ia_i1 \le a\_i \le 10^9, 0 \le b\_i \le a\_i, at least one b_i>0b\_i > 0) --- the number of people with the eye color ii and the lower bound of this number said by the traveler.

출력

Output two integers --- the number of the last day when the suicides will take place, and the total number of people committed suicide.

힌트

Let's show what happens in the first sample.

The person with the eye color 11 doesn't see anyone with the eye color 11 around, but hears that there is at least one person with this color. So they deduce who can be this person and commit suicide at the day 11.

All other people know that only two colors occur and that one person with the eye color 11 is dead. So they deduce all of them have eye color 22 and commit suicide at the day 22.