Election

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

문제

An election was held today. A total of nn parties, numbered 11 through nn, has participated in this election, and mm slots were distributed among the parties based on the number of votes each party got. The following algorithm was used for slot distribution:

Suppose that the parties 1,2,,n1, 2, \ldots, n got c_1,c_2,,c_nc\_1, c\_2, \ldots, c\_n votes, respectively. Let s=c_1+c_2++c_ns = c\_1 + c\_2 + \ldots + c\_n. First, for each ii, c_ism\lfloor \frac{c\_i}{s} \cdot m \rfloor slots are distributed to the party ii. Then, the remaining slots are distributed from the parties with the larger value of the fractional part of c_ism\frac{c\_i}{s} \cdot m, one slot per party. In case of a tie, the lower-indexed party has the priority.

You have the following information:

  • The parties 1,2,,n1, 2, \ldots, n got exactly a_1,a_2,,a_na\_1, a\_2, \ldots, a\_n votes, respectively.
  • The parties 1,2,,n1, 2, \ldots, n got at least b_1,b_2,,b_nb\_1, b\_2, \ldots, b\_n slots, respectively.

Compute the minimum possible number of total slots mm.

입력

The first line of input contains one integer nn (1n1001 \le n \le 100). Then nn lines follow, each contains a pair of integers a_ia\_i and b_ib\_i (1a_i10001 \le a\_i \le 1000, 0b_i1090 \le b\_i \le 10^9). You may assume that there exists at least one ii such that b_i1b\_i \ge 1.

출력

Print the minimum possible number of total slots mm.