Farmer John has received an order for exactly units of milk that he needs to fill immediately. Unfortunately, his fancy milking machine has just broken, and all he has are two milk pails with integer capacities and that he can use to measure milk. Both pails are initially empty.
Using these two pails, he can perform at most operations of the following types:
He can fill either pail completely.
He can empty either pail.
He can pour the contents of one pail into the other, stopping when the first pail becomes empty or the second pail becomes full, whichever happens first.
Although FJ realizes that he may not be able to end up with exactly units of milk in the two pails, please help him determine the minimum possible error between and the total amount of milk in the two pails. In other words, compute the minimum value of |m - m'| such that FJ can obtain a total of m' units of milk in the two pails.
One line contains four integers x, y, k, and m~(1 \le x, y \le 100, 1 \le k \le 100, 1 \le m \le 200).
Print the minimum possible difference between and the total amount of milk FJ can produce.
In two steps, FJ can obtain the following amounts of milk in his pails:
(0, 0) = 0 units
(14, 0) = 14 units
(0, 50) = 50 units
(0, 14) = 14 units
(14, 36) = 50 units
(14, 50) = 64 unitsThe closest FJ can get to units is units, for a difference of . Note that it would require an additional step to empty the first pail and obtain .
Example 1