题目描述
Problem Description
A company decided to distribute badges as prizes to contest participants.
According to estimates, $N$ badges are needed.
The company has three badge-making machines named A, B, and C.
Each machine produces a certain number of badges per minute: A produces $A$ badges, B produces $B$ badges, and C produces $C$ badges exactly one minute after being started.
These machines can only be operated in one-minute increments; they cannot be run for seconds (e.g., running machine A for 30 seconds to produce $A/2$ badges is not possible).
After running for one minute, each machine needs to cool down (idle) for two minutes. Therefore, the company decided to use the three machines in rotation. For example, the sequence could be machine A → machine B → machine C → machine A → machine B → machine C → machine A → ..., or machine B → machine A → machine C → machine B → machine A → machine C → machine B → ..., etc.
Since there is not much time until the contest, the company wants to collect the badges as quickly as possible. Write a program to calculate the minimum time required to produce at least $N$ badges by choosing the best sequence.
Input Format
The input is given from the standard input in the following format:
$ N $ $ A $ $ B $ $ C $
- The first line contains the number of badges needed, $N$ ($1 ≦ N ≦ 1,000$).
- The second line contains the number of badges produced by machine A in one minute, $A$ ($1 ≦ A ≦ 1,000$).
- The third line contains the number of badges produced by machine B in one minute, $B$ ($1 ≦ B ≦ 1,000$).
- The fourth line contains the number of badges produced by machine C in one minute, $C$ ($1 ≦ C ≦ 1,000$).
Output Format
Output the minimum time required to produce at least $N$ badges in one line. Ensure a newline at the end of the output.
Sample Input and Output
Sample Input #1
26
5
2
3
Sample Output #1
8
Sample Input #2
6
2
3
4
Sample Output #2
2
Sample Input #3
450
3
7
19
Sample Output #3
46
Notes/Hints
Sample Explanation 1
By operating the machines in the sequence machine A → machine B → machine C → machine A → machine B → machine C → machine A → machine B, it is possible to produce at least 26 badges in 8 minutes. The production and cumulative badge counts are as follows:
Time 1 2 3 4 5 6 7 8
Machine name A B C A B C A B
Production 5 2 3 5 2 3 5 2
Cumulative badges 5 7 10 15 17 20 25 27
Sample Explanation 2
It is not necessary to operate all machines.
输入格式
见题面 Input 部分
输出格式
见题面 Output 部分