The city of D consists of *n* towers, built consecutively on a straight line. The height of the tower that goes *i*-th (from left to right) in the sequence equals *h*<sub class="lower-index">*i*</sub>. The city mayor decided to rebuild the city to make it beautiful. In a beautiful city all towers are are arranged in non-descending order of their height from left to right.

The rebuilding consists of performing several (perhaps zero) operations. An operation constitutes using a crane to take any tower and put it altogether on the top of some other neighboring tower. In other words, we can take the tower that stands *i*-th and put it on the top of either the (*i* - 1)-th tower (if it exists), or the (*i* + 1)-th tower (of it exists). The height of the resulting tower equals the sum of heights of the two towers that were put together. After that the two towers can't be split by any means, but more similar operations can be performed on the resulting tower. Note that after each operation the total number of towers on the straight line decreases by 1.

Help the mayor determine the minimum number of operations required to make the city beautiful.
The first line contains a single integer *n* (1 ≤ *n* ≤ 5000) — the number of towers in the city. The next line contains *n* space-separated integers: the *i*-th number *h*<sub class="lower-index">*i*</sub> (1 ≤ *h*<sub class="lower-index">*i*</sub> ≤ 10<sup class="upper-index">5</sup>) determines the height of the tower that is *i*-th (from left to right) in the initial tower sequence.
from collections import deque
import heapq
import sys
readline=sys.stdin.readline

class Cumsum:
    def __init__(self,lst,mod=0):
        self.N=len(lst)
        self.mod=mod
        self.cumsum=[0]*(self.N+1)
        self.cumsum[0]=0
        for i in range(1,self.N+1):
            self.cumsum[i]=self.cumsum[i-1]+lst[i-1]
            if self.mod:
                self.cumsum[i]%=self.mod

    def __getitem__(self,i):
        if type(i)==int:
            if 0<=i<self.N:
                a,b=i,i+1
            elif -self.N<=i<0:
                a,b=i+self.N,i+self.N+1
            else:
                raise IndexError('list index out of range')
        else:
            a,b=i.start,i.stop
            if a==None or a<-self.N:
                a=0
            elif self.N<=a:
                a=self.N
            elif a<0:
                a+=self.N
            if b==None or self.N<=b:
                b=self.N
            elif b<-self.N:
                b=0
            elif b<0:
                b+=self.N
        s=self.cumsum[b]-self.cumsum[a]
        if self.mod:
            s%=self.mod
        return s

    def __setitem__(self,i,x):
        if -self.N<=i<0:
            i+=self.N
        elif not 0<=i<self.N:
            raise IndexError('list index out of range')
        self.cumsum[i+1]=self.cumsum[i]+x
        if self.mod:
            self.cumsum[i+1]%=self.mod

    def __str__(self):
        lst=[self.cumsum[i+1]-self.cumsum[i] for i in range(self.N)]
        if self.mod:
            for i in range(self.N):
                lst[i]%=self.mod
        return "["+", ".join(map(str,lst))+"]"

N=int(readline())
H=Cumsum(list(map(int,readline().split())))
inf=1<<15
inf=1<<15
dp=[[inf]*(N+1) for i in range(N+1)]
for i in range(1,N+1):
    dp[0][i]=i-1
for a in range(N):
    c=a+1
    for b in range(a+2,N+1):
        dp[a][b]=min(dp[a][b],dp[a][b-1]+1)
    for b in range(a+1,N+1):
        while (c<b) or (c!=N and H[a:b]>H[b:c]):
            c+=1
        if b<c and H[a:b]<=H[b:c]:
            dp[b][c]=dp[a][b]+c-b-1
ans=min(dp[i][N] for i in range(N))
print(ans)