You are playing a game of Pick It. You are given a list of positive integers, and you are allowed to select any number other than the first or last number in this list. When you pick a number, that number is removed from the board, and your score increases by the sum of the number that you picked and the sum of the neighbouring numbers.
For example, if the list contained
Given a list of numbers, what is the maximum score that you can obtain?
Input Specification
The input will consist of a number of test cases (at most 200 test cases). A test case is of the form
Output Specification
For each test case, output the maximum score attainable.
Sample Input
5 1 2 3 4 5
5 2 1 5 3 4
6 30 20 40 50 70 60
0
Output for Sample Input
30
31
570
Comments