#ABC231E. [ABC231E] Minimal payments
[ABC231E] Minimal payments
Score : points
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.
- $1=A_1 < \ldots
- is a multiple of for every .
Input
Input is given from Standard Input in the following format:
Output
Print the answer.
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 .
It is optimal to pay with seven -yen coins.