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 hi. 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.

Input

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 hi (1 ≤ hi ≤ 105) determines the height of the tower that is i-th (from left to right) in the initial tower sequence.

Output

Print a single integer — the minimum number of operations needed to make the city beautiful.

Examples

Input

5
8 2 7 3 1


Output

3


Input

3
5 2 1


Output

2
import sun.nio.cs.StreamDecoder;

import java.io.*;
import java.lang.reflect.Array;
import java.math.BigDecimal;
import java.sql.Time;
import java.util.*;

import java.math.BigInteger;

import static java.lang.Math.*;
import static java.math.BigInteger.*;
import static java.util.Arrays.*;


public class Main{

    void run(){
        Locale.setDefault(Locale.US);
        boolean oj;
        try {
            oj = System.getProperty("MYLOCAL") == null;
        } catch (Exception e) {
            oj = true;
        }
        try{
            if( oj ){
                sc  = new FastScanner( new InputStreamReader(System.in  ) );
                out = new PrintWriter(   new OutputStreamWriter(System.out) );
            } else{
                sc  = new FastScanner(new FileReader("in.txt") );
//                sc  = new FastScanner(new FileReader("D:\\JavaOlymp\\FatalError\\output.txt") );
                out = new PrintWriter(   new FileWriter("out.txt") );
            }
        } catch (Exception e) {
            System.exit(-1);
        }
//        long tB = System.currentTimeMillis();
        solve();
//        if( !oj ) System.err.println( "Time: " + (System.currentTimeMillis()-tB)/1e3 );
        out.flush();
    }


    class FastScanner{
        BufferedReader br;
        StringTokenizer st = new StringTokenizer("");
        FastScanner( InputStreamReader a ){
            br = new BufferedReader(a);
        }
        FastScanner( FileReader a ){
            br = new BufferedReader(a);
        }
        String next(){
            while( !st.hasMoreTokens() )
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    return null;
                }
            return st.nextToken();
        }
        String readLine(){
            try {
                return br.readLine();
            } catch (Exception e) {
                return null;
            }
        }
        int nextInt(){ return Integer.parseInt(next()); }
        long nextLong(){ return Long.parseLong(next()); }
    }

    FastScanner sc;
    PrintWriter out;
    PrintStream err = System.err;



    public static void main(String[] args){
        new Main().run();
//        new Thread( null, new Runnable() {
//            @Override
//            public void run() {
//                new Main().run();
//            }
//            }, "LOL", 256L * 1024 * 1024 / 2 ).run();
//        }, "LOL", 2000 * 1024 * 1024 ).run();
    }



    void TLE(){ for(;;); }


    void exit( int val ){
        out.flush();
        out.close();
        System.exit(val);
    }
    //////////////////////////////////////////////////////////////////////////////////////////

    final int inf = (int)1e8;
    int n;
    int[] a;
    int[] partSumA;
    int[][] dp, minVal;

    int getSum( int pos, int cnt ){
        int l = pos - cnt;
        if( l == -1 )
            return partSumA[pos];
        return partSumA[pos] - partSumA[l];
    }

    void solve(){
        err.println( "MEM: " + 4 *(2*5000*5000) / pow(1024,2) );

        n = sc.nextInt();
        a = new int[n];
        partSumA = new int[n];
        for (int i = 0; i < n; i++) {
            partSumA[i] = a[i] = sc.nextInt();
            if( i != 0 )
                partSumA[i] += partSumA[i-1];
        }

        dp = new int[n][n+1];
        minVal = new int[n][n+1];
        for( int[] i : dp ) fill( i, inf );
        for( int[] i : minVal ) fill( i, inf );
        for( int pos = 0; pos < n; ++pos ){
            for (int cnt = 1; cnt <= pos+1; cnt++) {
                int lPos = pos - cnt;
                if( lPos == -1 ){
                    dp[pos][cnt] = cnt - 1;
                }
                else{
                    int lCnt = bs(getSum(pos,cnt),lPos);
                    if( lCnt != -1 )
                        dp[pos][cnt] = min( dp[pos][cnt], cnt-1 + minVal[lPos][lCnt] );
                }
                ////////
                minVal[pos][cnt] = min( minVal[pos][cnt-1], dp[pos][cnt] );
            }
        }
        out.println( minVal[n-1][n] );
    }

    int bs(int curH, int lPos) {
        int l = 1, r = lPos + 1;
        while( l < r ){
            int m = (l + r + 1) / 2;
            if( getSum(lPos,m) <= curH ) l = m;
            else r = m - 1;
        }
        return (getSum(lPos,l) <= curH)? l : -1;
    }

}