#abc231e. [abc231_e]Minimal payments
[abc231_e]Minimal payments
Problem Statement
There are kinds of coins used in the Kingdom of Atcoder: -yen, -yen, , -yen coins.
Here, holds, and is a multiple of for every .
When paying for a product worth yen using just these coins, what is the minimum total number of coins used in payment and returned as change?
Accurately, when is an integer at least , find the minimum sum of the number of coins needed to represent exactly yen and the number of coins needed to represent exactly yen.
Constraints
- All values in input are integers.
- is a multiple of for every .
Input
Input is given from Standard Input in the following format:
Output
Print the answer.
Sample Input 1
3 87
1 10 100
Sample Output 1
5
If we pay with one -yen coin and receive one -yen coin and three -yen coins as the change, the total number of coins will be .
Sample Input 2
2 49
1 7
Sample Output 2
7
It is optimal to pay with seven -yen coins.
Sample Input 3
10 123456789012345678
1 100 10000 1000000 100000000 10000000000 1000000000000 100000000000000 10000000000000000 1000000000000000000
Sample Output 3
233