import std.stdio;
import std.ascii;
import core.stdc.stdio;
import std.algorithm;

int main()
{
    int n = readInt!int;
    auto a = new long[](n);
    foreach(ref ai; a) ai = readInt!long;
    int pos = cast(int) a.count!(ai => ai >= 0);
    long[][] maxSum = new long[][](n + 1, n + 1);
    maxSum[0][0] = (a[0] < 0)? 0 : a[0];
    foreach(i; 1 .. n)
    {
        maxSum[i][0] = (a[i] < 0)? maxSum[i-1][0] : (maxSum[i-1][0] + a[i]);
    }
    foreach(p; 1 .. n)
    {
        foreach(i; 0 .. n)
        {
            if (a[i] < 0)
            {
                if (i == 0)
                {
                    maxSum[i][p] = -1;
                }
                else
                {
                    maxSum[i][p] = max(maxSum[i-1][p], maxSum[i-1][p-1] + a[i]);
                }
            }
            else
            {
                if (i == 0)
                {
                    maxSum[i][p] = -1;
                }
                else
                {
                    maxSum[i][p] = (maxSum[i-1][p] >= 0)? (maxSum[i-1][p] + a[i]) : maxSum[i-1][p];
                }
            }
        }
    }
    int p = 0;
    while (p + 1 < n && maxSum[n-1][p + 1] >= 0)
    {
        p++;
    }
    writeln(pos + p);
    return 0;
}






/* INPUT ROUTINES */
int currChar;
static this()
{
    currChar = getchar();
}
char topChar()
{
    return cast(char) currChar;
}
void popChar()
{
    currChar = getchar();
}
auto readInt(T)()
{
    T num = 0;
    int sgn = 0;
    while (topChar.isWhite) popChar;
    while (topChar == '-' || topChar == '+') { sgn ^= (topChar == '-'); popChar; }
    while (topChar.isDigit) { num *= 10; num += (topChar - '0'); popChar; }
    if (sgn) return -num; return num;
}
string readString()
{
    string res = "";
    while (topChar.isWhite) popChar;
    while (!topChar.isWhite) { res ~= topChar; popChar; }
    return res;
}
