CSES - KILO 2018 2/5 - Yellow Yacht
  • Time limit: 2.00 s
  • Memory limit: 512 MB

Uolevi wants a yacht, but he is on a tight budget of mm euros, so he has decided to build his own.

He can spend money on buoyancy, size, and yellow paint. Formally, let bb be the amount of euros he spends on buoyancy, ss be the amount of euros spent on size, and yy the amount of euros spent on yellow paint. The value of the boat will be

f(b)+f(s)+f(y)f(b) + f(s) + f(y)

where f:[0,m][0,109]f: [0, m] \mapsto [0, 10^{9}] is some function you are given. Find the maximum value the boat can have when Uolevi spends at most mm euros in total, that is, he chooses bb, ss, yy such that

  • 0b,s,y0 \leq b, s, y
  • b+s+ymb + s + y \leq m

Input

The first line contains an integer mm.

The next line contains m+1m+1 integers: f(0),,f(m)f(0), \dots, f(m).

Output

Output a single integer: the maximum value the boat can have.

Constraints

  • 0m1040 \leq m \leq 10^{4}
  • 0f(i)1090 \leq f(i) \leq 10^{9} for all 0im0 \leq i \leq m

Example

Input:

11
1 0 5 9 10 2 16 13 0 19 27 6

Output:

30

Explanation:
Uolevi can choose b=2b = 2, s=3s = 3, y=6y = 6 to achieve 30=5+9+16=f(b)+f(s)+f(y)30 = 5 + 9 + 16 = f(b) + f(s) + f(y).

Example 2

Input:

0
1000000000

Output:

3000000000