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 java.io.*;
import java.util.*;

public class D implements Runnable{
	public static void main (String[] args) {new Thread(null, new D(), "_cf", 1 << 28).start();}

	public void run() {
		FastScanner fs = new FastScanner();
		PrintWriter out = new PrintWriter(System.out);
		System.err.println("Go!");

		int n = fs.nextInt();
		int[] a = fs.nextIntArray(n);
		int[][] values = new int[n][];
		for(int i = 0; i < n; i++) {
			values[i] = new int[i];
			for(int j = i-1, k = 0; j >= 0; j--, k++) {
				values[i][k] = a[j];
				if(k > 0) values[i][k] += values[i][k-1];
			}
		}
		int oo = (int)1e9;
		int res = n-1;
		int[][] dp = new int[n][];
		for(int i = n-1; i >= 0; i--) {
			dp[i] = new int[i];
			Arrays.fill(dp[i], oo);
			int sum = 0;
			res = n-1;
			for(int j = i; j < n; j++) {
				sum += a[j];
				int ret = j-i;
				if(j+1 < n) {
					int next = dp[j+1][j-i];
					ret = Math.min(oo, ret+next);
				}
				if(ret == oo) continue;
				res = Math.min(res, ret);
				int next = floor(values[i], sum);
				if(next != -1) dp[i][next] = Math.min(dp[i][next], ret);
			}
			for(int j = dp[i].length-1; j >= 0; j--) {
				if(j+1 < dp[i].length) dp[i][j] = Math.min(dp[i][j], dp[i][j+1]);
			}
		}
		out.println(res);
		out.close();
	}
	
	int ceil(int[] a, int key) {
		int res = -1;
		int lo = 0, hi = a.length-1;
		for(int bs = 0; bs < 50 && lo <= hi; bs++) {
			int mid = (lo+hi)/2;
			if(a[mid] >= key) {
				res = mid;
				hi = mid-1;
			}
			else {
				lo = mid+1;
			}
		}
		return res;
	}
	
	int floor(int[] a, int key) {
		int res = -1;
		int lo = 0, hi = a.length-1;
		for(int bs = 0; bs < 50 && lo <= hi; bs++) {
			int mid = (lo+hi)/2;
			if(a[mid] <= key) {
				res = mid;
				lo = mid+1;
			}
			else {
				hi = mid-1;
			}
		}
		return res;
	}

	class FastScanner {
		public int BS = 1<<16;
		public char NC = (char)0;
		byte[] buf = new byte[BS];
		int bId = 0, size = 0;
		char c = NC;
		double num = 1;
		BufferedInputStream in;

		public FastScanner() {
			in = new BufferedInputStream(System.in, BS);
		}

		public FastScanner(String s) throws FileNotFoundException {
			in = new BufferedInputStream(new FileInputStream(new File(s)), BS);
		}

		public char nextChar(){
			while(bId==size) {
				try {
					size = in.read(buf);
				}catch(Exception e) {
					return NC;
				}                
				if(size==-1)return NC;
				bId=0;
			}
			return (char)buf[bId++];
		}

		public int nextInt() {
			return (int)nextLong();
		}

		public long nextLong() {
			num=1;
			boolean neg = false;
			if(c==NC)c=nextChar();
			for(;(c<'0' || c>'9'); c = nextChar()) {
				if(c=='-')neg=true;
			}
			long res = 0;
			for(; c>='0' && c <='9'; c=nextChar()) {
				res = (res<<3)+(res<<1)+c-'0';
				num*=10;
			}
			return neg?-res:res;
		}

		public double nextDouble() {
			double cur = nextLong();
			return c!='.' ? cur:cur+nextLong()/num;
		}

		public String next() {
			StringBuilder res = new StringBuilder();
			while(c<=32)c=nextChar();
			while(c>32) {
				res.append(c);
				c=nextChar();
			}
			return res.toString();
		}

		public String nextLine() {
			StringBuilder res = new StringBuilder();
			while(c<=32)c=nextChar();
			while(c!='\n') {
				res.append(c);
				c=nextChar();
			}
			return res.toString();
		}

		public boolean hasNext() {
			if(c>32)return true;
			while(true) {
				c=nextChar();
				if(c==NC)return false;
				else if(c>32)return true;
			}
		}
		
		public int[] nextIntArray(int n) {
			int[] res = new int[n];
			for(int i = 0; i < n; i++) res[i] = nextInt();
			return res;
		}
		
	}

}