A wide river has
The cost of building a bridge section between pillars
What is the minimum possible cost of building the bridge that connects the first and last pillar?
Input
The first line contains the number of pillars,
Output
Output the minimum cost for building the bridge. Note that it can be negative.
Constraints
Subtask 1 (30 points)
Subtask 2 (30 points)
- optimal solution includes at most 2 additional pillars (besides the first and last)
Subtask 3 (40 points)
- no additional constraints
Sample Input 1
6
3 8 7 1 6 6
0 -1 9 1 2 0
Sample Output 1
17
Comments
Since the original data were weak, an additional test case was added to subtask
.