Earth currently has trees. We estimate that, without human interference, this value increases by each year (rounding down). However, we require wood as a natural resource, so we must cut down trees each year.
Assume the number of trees increases by before humans cut them down for the year. Determine the maximum value of such that after years, there are at least trees remaining on Earth.
Constraints
The integer will be given such that there is guaranteed a non-negative answer for .
Input Specification
The first and only line will contain space-separated integers , , , and .
Output Specification
Output the maximum value of such that after years, there are at least trees remaining on Earth.
Sample Input 1
100 90 3 1
Sample Output 1
105
Explanation for Sample Output 1
After 1 year: the number of trees increases from to . We cut down trees, leaving us with .
After 2 years: the number of trees increases from to . We cut down trees, leaving us with .
After 3 years: the number of trees increases from to . We cut down trees, leaving us with .
Because we have tree remaining after years, is the maximum value for .
Sample Input 2
100000000000000 100 15 3000000000
Sample Output 2
100003051759392
Explanation for Sample Output 2
Make sure to use -bit integers for this problem.
Comments