There are N teams in a software company. The ith team has Bi employees in it and a total budget of Ai units of money. Each team has to divide their budget within employees equally. But for some teams it's not possible. Therefore the company has to perform revisions in their teams' budget. In one revision, to revise the budget of ith team, the budget of first i teams has to be increased by 1. Your task is to find the minimum number of revisions needed so that for each team, equal distribution of their budget among the employees are possible.
Sample case: (A1 B1), (A2 B2), (A3 B3) : (1 1), (3 7), (5 4).
Solution is 4. Initial budget (1,3,5) -> (2,4,5) -> (5,7,8)