407435: GYM102791 A Christmas Ornaments

Memory Limit:256 MB Time Limit:1 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

A. Christmas Ornamentstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard output

Monocarp decided to buy ball ornaments to decorate his Christmas tree. There are only three colors of ornaments in the shop nearby: red, yellow, and blue. Fortunately, there are infinitely many ornaments of each color.

One red ornament costs $$$r$$$ burles, one yellow ornament — $$$y$$$ burles, and one blue ornament — $$$b$$$ burles.

Monocarp has $$$n$$$ burles and would like to buy as many ornaments as possible. But he considers Christmas tree to be beautifully decorated only if the numbers of ornaments of each color differ by not more than one. More formally, if Monocarp will buy $$$cnt_r$$$ red ornaments, $$$cnt_y$$$ yellow ornaments, and $$$cnt_b$$$ blue ornaments then the following conditions should be fulfilled: $$$|cnt_r - cnt_y| \le 1$$$, $$$|cnt_r - cnt_b| \le 1$$$, $$$|cnt_y - cnt_b| \le 1$$$.

Calculate the maximum possible total number of ornaments Monocarp can buy in such a way that the numbers of ornaments of each color differ by not more than one.

Input

The first line contains one integer $$$n$$$ ($$$1 \le n \le 1000$$$) — the amount of money Monokarp has.

The second line contains one integer $$$r$$$ ($$$1 \le r \le n$$$) — the cost of one red ornament.

The third line contains one integer $$$y$$$ ($$$1 \le y \le n$$$) — the cost of one yellow ornament.

The fourth line contains one integer $$$b$$$ ($$$1 \le b \le n$$$) — the cost of one blue ornament.

Output

Print the maximum possible total number of ornaments Monocarp can buy in such a way that the numbers of ornaments of each color differ by not more than one.

ExamplesInput
12
2
2
2
Output
6
Input
26
1
4
7
Output
7
Input
17
4
2
3
Output
5
Input
100
100
100
100
Output
1
Note

In the first sample, Monocarp can buy two ornaments of each color and will spend all $$$12$$$ burles he has. In total, he can buy at most $$$6$$$ ornaments.

In the second sample, Monocarp can buy $$$3$$$ red ornaments, $$$2$$$ yellow ornaments, and $$$2$$$ blue ornaments and will spend $$$3 \cdot 1 + 2 \cdot 4 + 2 \cdot 7 = 25$$$ burles. In total Monocarp can buy at most $$$7$$$ ornaments. Monocarp still has $$$1$$$ burle left, but he won't buy extra red ornament, since it will break the beautiful decoration of the Christmas tree described in the statement.

In the third sample, Monocarp can buy $$$1$$$ red ornament, $$$2$$$ yellow ornaments, and $$$2$$$ blue ornaments and will spend $$$1 \cdot 4 + 2 \cdot 2 + 2 \cdot 3 = 14$$$ burles. In total, he can buy at most $$$5$$$ ornaments.

加入题单

上一题 下一题 算法标签: