Milk Pails (Bronze)#10580

Milk Pails (Bronze)

1 second
128 megabytes
Easy

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:

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.

Input

Three integers , and m~(1 \le x < y < m, 1 \le m \le 1000).

Output

Print the maximum amount of milk that Farmer John can add to the pail with capacity .

Examples

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

Loading
Loading