QOJ.ac

QOJ

Time Limit: 2 s Memory Limit: 256 MB Total points: 100

#21162. Milk Pails

Statistics

Farmer John has received an order for exactly $M$ units of milk ($1 \leq M \leq 1,000$) that he needs to fill right away. Unfortunately, his fancy milking machine has just become broken, and all he has are three milk pails of integer sizes $X$, $Y$, and $M$ ($1 \leq X < Y < M$). All three pails are initially empty. Using these three pails, he can perform any number of the following two types of operations:

  • He can fill the smallest pail (of size $X$) completely to the top with $X$ units of milk and pour it into the size-$M$ pail, as long as this will not cause the size-$M$ pail to overflow.
  • He can fill the medium-sized pail (of size $Y$) completely to the top with $Y$ units of milk and pour it into the size-$M$ pail, as long as this will not cause the size-$M$ pail to overflow.

Although FJ realizes he may not be able to completely fill the size-$M$ pail, please help him determine the maximum amount of milk he can possibly add to this pail.

Input

The first, and only line of input, contains $X$, $Y$, and $M$, separated by spaces.

Output

Output the maximum amount of milk FJ can possibly add to the size-$M$ pail.

Examples

Input 1

17 25 77

Output 1

76

In this example, FJ fills the pail of size 17 three times and the pail of size 25 once, accumulating a total of 76 units of milk.

Problem credits: Brian Dean

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.