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 three milk pails with integer capacities , , and . All three pails are initially empty.
Using these three pails, Farmer John can perform any number of the following two operations:
He can fill the smallest pail (with capacity ) completely with units of milk and pour it into the pail with capacity , provided that this does not cause the -unit pail to overflow.
He can fill the medium-sized pail (with capacity ) completely with units of milk and pour it into the pail with capacity , provided that this does not cause the -unit pail to overflow.
Although Farmer John realizes that he may not be able to completely fill the pail with capacity , please help him determine the maximum amount of milk he can add to this pail.
Three integers , and m~(1 \le x < y < m, 1 \le m \le 1000).
Print the maximum amount of milk that Farmer John can add to the pail with capacity .
In this example, Farmer John fills the pail with capacity three times and the pail with capacity once, accumulating a total of units of milk.
Example 1