#include<stdio.h>
#include<string.h>
#define MAXN 5005
int dp[MAXN][MAXN], inf = 1000000000;
int main() {
int n, a[MAXN],i,j;
for(i = 1; i <= n; i++) {
}
for(i = 0; i <= n; i++) {
for(j = 0; j <= n; j++) {
dp[i][j] = inf;
}
}
dp[0][0] = 0;
for(i = 1; i <= n; i++) {
int k = -1, s = 0;
for(j = i; j <= n; j++) {
s += a[j];
while(k+1<=n && dp[i-1][k+1] <= s) {
k++;
}
if(k>=0 && dp[j][k+1]>s) {
dp[j][k+1]=s;
}
}
for(k = n-1; k >= 0; k--) {
if(dp[i][k]>dp[i][k+1]) {
dp[i][k]=dp[i][k+1];
}
}
}
int res = inf,k;
for(k = 1; k <= n; k++) {
if(dp[n][k] < inf) {
res = k;
}
}
}
I2luY2x1ZGU8c3RkaW8uaD4KI2luY2x1ZGU8c3RyaW5nLmg+CgojZGVmaW5lIE1BWE4gNTAwNQoKaW50IGRwW01BWE5dW01BWE5dLCBpbmYgPSAxMDAwMDAwMDAwOwoKaW50IG1haW4oKSB7CiAgICBpbnQgbiwgYVtNQVhOXSxpLGo7CglzY2FuZigiJWQiLCAmbik7Cglmb3IoaSA9IDE7IGkgPD0gbjsgaSsrKSB7CgkJc2NhbmYoIiVkIiwgJmFbaV0pOwoJfQoJCglmb3IoaSA9IDA7IGkgPD0gbjsgaSsrKSB7CgkJZm9yKGogPSAwOyBqIDw9IG47IGorKykgewoJCQlkcFtpXVtqXSA9IGluZjsKCQl9Cgl9CglkcFswXVswXSA9IDA7CgkKCWZvcihpID0gMTsgaSA8PSBuOyBpKyspIHsKCQlpbnQgayA9IC0xLCBzID0gMDsKCQlmb3IoaiA9IGk7IGogPD0gbjsgaisrKSB7CgkJCXMgKz0gYVtqXTsKCQkJd2hpbGUoaysxPD1uICYmIGRwW2ktMV1baysxXSA8PSBzKSB7CgkJCQlrKys7CgkJCX0KCQkJCgkJCWlmKGs+PTAgJiYgZHBbal1baysxXT5zKSB7CgkJCQlkcFtqXVtrKzFdPXM7C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