atcoder#AGC009A. Multiple Array
Multiple Array
Score : points
Problem Statement
There are an integer sequence consisting of terms, and buttons. When the -th button is pressed, the values of the terms from the first through the -th are all incremented by .
There is also another integer sequence . Takahashi will push the buttons some number of times so that for every , will be a multiple of .
Find the minimum number of times Takahashi will press the buttons.
Constraints
- All input values are integers.
Input
The input is given from Standard Input in the following format:
:
Output
Print an integer representing the minimum number of times Takahashi will press the buttons.
3
3 5
2 7
9 4
7
Press the first button twice, the second button twice and the third button three times.
7
3 1
4 1
5 9
2 6
5 3
5 8
9 7
22