Drilling

No attempts yetTime limit1sMemory limit128 MB

Problem

Byteman leads a team searching for crude-oil reservoirs. The team has already drilled two boreholes: they found oil at point AA and confirmed that there is no oil at point BB. The reservoir occupies a connected piece of the segment ABAB with one end exactly at AA. Byteman now has to determine how far the reservoir reaches along ABAB.

This is not simple, because the drilling speed depends on the location, and the team can drill in only one place at a time. Byteman wants to know in advance how much time he will need, in the worst case, to pinpoint the reservoir's boundary.

Split the segment ABAB into n+1n + 1 equal parts. Place AA at coordinate 00 and BB at coordinate n+1n + 1; then the candidate points lie at coordinates 1,2,,n1, 2, \ldots, n. Oil reaches coordinate 00 (point AA) but not coordinate n+1n + 1 (point BB), so the boundary is the largest coordinate among 1,2,,n1, 2, \ldots, n that still contains oil (it is 00 if none of them do). Drilling a borehole at point ii takes tit_i units of time and reveals whether oil is present there.

Design a drilling plan that minimizes the worst-case total time needed to identify the reservoir's boundary, and report that time.

Input

The first line contains one integer nn (1n20001 \le n \le 2000).

The second line contains nn integers t1,t2,,tnt_1, t_2, \ldots, t_n (1ti1061 \le t_i \le 10^6), separated by single spaces.

Output

Print a single integer: the smallest worst-case total drilling time that guarantees Byteman can identify the reservoir's boundary.

Hint

Suppose Byteman drills point 11 first, spending time 88. If oil is found there, he still has to learn how far the reservoir reaches to the right, which takes two more boreholes costing 3636 in the worst case, for a total of 4444.

Starting at point 22 turns out to be better. If point 22 has no oil, checking point 11 alone finishes the job. Otherwise, in the worst case he drills points 33 and 44 and finishes with total time 4242. Hence 4242 is optimal for this sample.