In a pond there are stones in a row. A frog must go from stone 1 to , in principle going consecutively through stones 2, 3, … The problem is that the frog is very greedy, and it will not help eating all the flies around each stone that it visits. To avoid fattening too much, the frog can make up to big forward jumps, each one over at most two stones (that is, from it can jump, at most, up to ). What is the minimum number of flies that the frog will eat?
Input consists of several cases. Every case begins with and , followed by the number of flies around each stone ( natural numbers between 0 and ). Assume , and .
For every case, print the minimum number of flies that the frog will eat.
Input
2 0 23 33 2 1 23 33 4 0 100 42 3 1000 4 1 100 42 3 1000 3 1 10000 10000 10000 5 1 1000 1000 0 1000 1000 5 2 1000 1000 0 1000 1000 5 4 1000 1000 0 1000 1000
Output
56 56 1145 1100 20000 3000 2000 2000