AtCoder Grand Contest 009
A
Multiple Array
AtCoder
⌀ 759
原题
←B →
翻译中…

Problem Statement

翻译中…

There are an integer sequence $A_1,...,A_N$ consisting of $N$ terms, and $N$ buttons. When the $i$-th $(1 ≦ i ≦ N)$ button is pressed, the values of the $i$ terms from the first through the $i$-th are all incremented by $1$.

翻译中…

There is also another integer sequence $B_1,...,B_N$. Takahashi will push the buttons some number of times so that for every $i$, $A_i$ will be a multiple of $B_i$.

翻译中…

Find the minimum number of times Takahashi will press the buttons.

翻译中…

Constraints

翻译中…
  • All input values are integers.
  • $1 ≦ N ≦ 10^5$
  • $0 ≦ A_i ≦ 10^9(1 ≦ i ≦ N)$
  • $1 ≦ B_i ≦ 10^9(1 ≦ i ≦ N)$
翻译中…

Input

翻译中…

The input is given from Standard Input in the following format:

翻译中…

N
A_1 B_1
:
A_N B_N

翻译中…

Output

翻译中…

Print an integer representing the minimum number of times Takahashi will press the buttons.

翻译中…

样例

Input #1
3
3 5
2 7
9 4
Output #1
7
Press the first button twice, the second button twice and the third button three times.
Input #2
7
3 1
4 1
5 9
2 6
5 3
5 8
9 7
Output #2
22
题目信息
题号
agc009_a
时间限制
2 s
内存限制
256 MB

题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。