Welcome to Innopolis city. Throughout the whole year, Innopolis citizens suffer from everlasting city construction. 

From the window in your room, you see the sequence of n hills, where i-th of them has height a_{i}. The Innopolis administration wants to build some houses on the hills. However, for the sake of city appearance, a house can be only built on the hill, which is strictly higher than neighbouring hills (if they are present). For example, if the sequence of heights is 5, 4, 6, 2, then houses could be built on hills with heights 5 and 6 only.

The Innopolis administration has an excavator, that can decrease the height of an arbitrary hill by one in one hour. The excavator can only work on one hill at a time. It is allowed to decrease hills up to zero height, or even to negative values. Increasing height of any hill is impossible. The city administration wants to build k houses, so there must be at least k hills that satisfy the condition above. What is the minimum time required to adjust the hills to achieve the administration's plan?

However, the exact value of k is not yet determined, so could you please calculate answers for all k in range $1 \leq k \leq \lceil \frac{n}{2} \rceil$? Here $\lceil \frac{n}{2} \rceil$ denotes n divided by two, rounded up.


-----Input-----

The first line of input contains the only integer n (1 ≤ n ≤ 5000)—the number of the hills in the sequence.

Second line contains n integers a_{i} (1 ≤ a_{i} ≤ 100 000)—the heights of the hills in the sequence.


-----Output-----

Print exactly $\lceil \frac{n}{2} \rceil$ numbers separated by spaces. The i-th printed number should be equal to the minimum number of hours required to level hills so it becomes possible to build i houses.


-----Examples-----
Input
5
1 1 1 1 1

Output
1 2 2 

Input
3
1 2 3

Output
0 2 

Input
5
1 2 3 2 2

Output
0 1 3 



-----Note-----

In the first example, to get at least one hill suitable for construction, one can decrease the second hill by one in one hour, then the sequence of heights becomes 1, 0, 1, 1, 1 and the first hill becomes suitable for construction.

In the first example, to get at least two or at least three suitable hills, one can decrease the second and the fourth hills, then the sequence of heights becomes 1, 0, 1, 0, 1, and hills 1, 3, 5 become suitable for construction.

Difficulty: competition

Starter code:

Solutions:
def main():
    n, a, z = int(input()), 0, 10 ** 10
    b, *cc = list(map(int, input().split()))
    dp = [(0, z, z), (z, 0, z), *[(z, z, z)] * ((n - 1) // 2)]
    for i, c in enumerate(cc, 1):
        u, v, w = dp[i // 2 + 1]
        dz = max(0, c - b + 1)
        du = max(0, b - c + 1)
        dw = max(0, min(a - 1, b) - c + 1)
        for j in range(i // 2, -1, -1):
            x, y, z = u, v, w
            u, v, w = dp[j]
            dp[j + 1] = (x if x < z else z, min(u + du, w + dw), y + dz)
        a, b = b, c
    print(' '.join(map(str, list(map(min, dp[1:])))))


def __starting_point():
    main()

__starting_point()

from sys import stdin
from math import ceil
n=int(stdin.readline().strip())
s=tuple([0]+list(map(int,stdin.readline().strip().split()))+[0])
lim=ceil(n/2)+1
dp=[[2000000002 for i in  range(n+1)] for j in range(lim)]
vis=[[False for i in  range(n+1)] for j in range(lim)]
for  i in range(n+1):
    dp[0][i]=0
ans=[0 for i in range(lim-1)]
for i in range(1,lim):
    for j in range(1,n+1):
        x=0
        y=s[j-1]
        if vis[i-1][j-2]:
            y=min(y,s[j-2]-1)
        if y>=s[j]:
            x=y-s[j]+1
        if s[j+1]>=s[j]:
            x+=s[j+1]-s[j]+1
        if j==1:
            if dp[i-1][0]+x<=dp[i][j-1]:
                vis[i][j]=True
                dp[i][j]=dp[i-1][0]+x
            else:
                dp[i][j]=dp[i][j-1]
        else:
            if dp[i-1][j-2]+x<=dp[i][j-1]:
                vis[i][j]=True
                dp[i][j]=dp[i-1][j-2]+x
            else:
                dp[i][j]=dp[i][j-1]
    ans[i-1]=dp[i][-1]
print(*ans)


from sys import stdin
from math import ceil
n=int(stdin.readline().strip())
s=tuple([0]+list(map(int,stdin.readline().strip().split()))+[0])
lim=ceil(n/2)+1
dp=[[2000000002 for i in  range(n+1)] for j in range(lim)]
vis=[[False for i in  range(n+1)] for j in range(lim)]
for  i in range(n+1):
    dp[0][i]=0
ans=[0 for i in range(lim-1)]
for i in range(1,lim):
    for j in range(1,n+1):
        x=0
        y=s[j-1]
        if vis[i-1][j-2]:
            y=min(y,s[j-2]-1)
        if y>=s[j]:
            x=y-s[j]+1
        if s[j+1]>=s[j]:
            x+=s[j+1]-s[j]+1
        if j==1:
            if dp[i-1][0]+x<=dp[i][j-1]:
                vis[i][j]=True
                dp[i][j]=dp[i-1][0]+x
            else:
                dp[i][j]=dp[i][j-1]
        else:
            if dp[i-1][j-2]+x<=dp[i][j-1]:
                vis[i][j]=True
                dp[i][j]=dp[i-1][j-2]+x
            else:
                dp[i][j]=dp[i][j-1]
    ans[i-1]=dp[i][-1]
print(*ans)

import math
import sys
import time

length = int(input())
# heights = [random.randint(0, 500) for x in range(0, length)]
heights = [int(x) for x in input().split(' ')]
start = time.time()
cache = {}
cache[(length, heights[length - 1])] = []
cache[(length, heights[length - 2] - 1)] = []

def min_list(modifyable, modifier):
    for i in range(0, len(modifier)):
        if (i == len(modifyable)):
            modifyable.append(modifier[i])
        else:
            modifyable[i] = min(modifyable[i], modifier[i])

def new_step(index, last_height):
    height = heights[index]
    if index == length - 1:
        return [max(0, last_height - height + 1)]
    
    next_height = heights[index + 1]

    result = cache[(index + 1, height)].copy()
    b = cache[(index + 2, next_height)]
    min_list(result, b)
    
    new_difference = max(0, last_height - height + 1) + max(0, next_height - height + 1)
    c = [new_difference]
    d = cache[(index + 2, min(next_height, height - 1))]
    for value in d:
        c.append(value + new_difference)
    min_list(result, c)
    return result

i = length - 1
while i > 0:
    cache[(i, heights[i - 1])] = new_step(i, heights[i - 1])
    
    if i > 1 and heights[i - 2] <= heights[i - 1]:
        cache[(i, heights[i - 2] - 1)] = new_step(i, heights[i - 2] - 1)

    i -= 1

print(' '.join(map(str, new_step(0, -sys.maxsize))))
end = time.time()
# print(end - start)