Problems
Bessie the cow has in her possession
If you have at least
c_B chips of type B, exchangec_B chips of type B forc_A chips of type A (1≤c_A,c_B≤10^9 ).
Determine the minimum non-negative integer
Input
The first line contains
Then follow
Output
Output the answer for each test on a separate line.
Note: The large size of integers involved in this problem may require the use of 64-bit integer data types (e.g., a "long long" in C/C++).
Subtask
| # | Score | Condition |
|---|---|---|
| #1 | 10 | |
| #2 | 20 | |
| #3 | 30 | |
| #4 | 40 | No additional constraints |
Example #1
2
2 3 1 1 6
2 3 1 1 4
1
0
Example #2
5
0 0 2 3 5
0 1 2 3 5
1 0 2 3 5
10 10 2 3 5
0 0 1 1000000000 1000000000
9
8
7
0
1000000000000000000
For the first test, Bessie initially starts with no chips. If she receives any 9 additional chips, she can perform the operation to end up with at least 5 chips of type A. For example, if she receives 2 chips of type A and 7 chips of type B, she can perform the operation twice to end up with 6≥5 chips of type A. However, if she only receive 8 chips of type B, she can only end up with 4<5 chips of type A.
For the fourth test, she already has enough chips of type A from the start.