Time limit
2s
Memory limit
128 MB
Sejun is playing a guitar-picking game against an opponent.
Before the game starts, N guitar cases are arranged in a circle. Each case contains one guitar. For each i with 1 <= i < N, case i is adjacent to case i+1, and case N is also adjacent to case 1.
A group is a nonempty consecutive set of guitars that have not been taken yet. On every turn, the current player must choose and take exactly one guitar from every remaining group. When a guitar is taken, the group containing it may split into the remaining consecutive parts on its left and right; empty parts are not groups.
For example, when N = 8, one possible game can proceed as follows.
Both players keep all guitars they take. Sejun wants to maximize the total value of the guitars he takes. Given the number of guitars and their values, compute the maximum total value Sejun can obtain when he moves first and both players play optimally.
The first line contains the number of guitars N. N is a natural number between 2 and 50, inclusive.
The second line contains N guitar values in circular order. Each value is a natural number between 1 and 10,000, inclusive, and the values are separated by spaces.
Print the maximum possible total value of the guitars Sejun can obtain.