#include <bits/stdc++.h>
#define REP(i, N) for (int i = 0; i < (int)N; i++)
#define FOR(i, a, b) for (int i = a; i < (int)b; i++)
#define ALL(x) (x).begin(), (x).end()

using namespace std;

constexpr int inf = 1 << 30;
constexpr long long llinf = 1LL << 62;
constexpr int mod = 1000000007;  // 998244353;
constexpr int dy[4] = {-1, 0, 1, 0}, dx[4] = {0, -1, 0, 1};

using ll = long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

inline int popcount(ll x) { return __builtin_popcountll(x); }
inline int div2num(ll x) { return __builtin_ctzll(x); }
inline bool bit(ll x, int b) { return (x >> b) & 1; }

template <class T>
bool chmax(T& a, const T& b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool chmin(T& a, const T& b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}

namespace FastIO {
struct Pre {
  char ptr[10000 * 4];
  int rd[1 << 16];
  int tenpow[4];
  constexpr Pre() : ptr(), rd(), tenpow() {
    for (int i = 0; i < 10000; ++i) {
      int j = i;
      int temp = 0;
      for (int t = 3; t >= 0; --t) {
        ptr[i * 4 + t] = j % 10 + '0';
        temp += (1 << ((3 - t) * 4)) * (j % 10);
        j /= 10;
      }
      rd[temp] = i;
    }
    tenpow[0] = 1;
    tenpow[1] = 10;
    tenpow[2] = 100;
    tenpow[3] = 1000;
  }
} constexpr ptr;
static constexpr size_t buf_size = 1 << 20;
char buf_in[buf_size], buf_out[buf_size];
size_t pt_in = 0, pt_out = 0, tail_in = 0;
inline size_t num_digits(long long x) {
  if (x >= (long long)1e9) {
    if (x >= (long long)1e18) return 19;
    if (x >= (long long)1e17) return 18;
    if (x >= (long long)1e16) return 17;
    if (x >= (long long)1e15) return 16;
    if (x >= (long long)1e14) return 15;
    if (x >= (long long)1e13) return 14;
    if (x >= (long long)1e12) return 13;
    if (x >= (long long)1e11) return 12;
    if (x >= (long long)1e10) return 11;
    return 10;
  } else {
    if (x >= (long long)1e8) return 9;
    if (x >= (long long)1e7) return 8;
    if (x >= (long long)1e6) return 7;
    if (x >= (long long)1e5) return 6;
    if (x >= (long long)1e4) return 5;
    if (x >= (long long)1e3) return 4;
    if (x >= (long long)1e2) return 3;
    if (x >= (long long)1e1) return 2;
    return 1;
  }
}
inline void load() {
  memcpy(buf_in, buf_in + pt_in, tail_in - pt_in);
  size_t width = tail_in - pt_in;
  tail_in = width + fread(buf_in + width, 1, buf_size - width, stdin);
  pt_in = 0;
}
inline void flush() {
  fwrite(buf_out, 1, pt_out, stdout);
  pt_out = 0;
}
inline void scan(char& c) { c = buf_in[pt_in++]; }
template <class T>
inline void scan(T& x) {
  if (pt_in + 32 > tail_in) load();
  char c;
  bool minus = 0;
  x = 0;
  scan(c);
  if (c == '-') {
    minus = 1;
    scan(c);
  }
  while (c >= '0') {
    x = x * 10 + (c & 15);
    scan(c);
  }
  if (minus) x = -x;
}
inline void print(char c) { buf_out[pt_out++] = c; }
template <class T>
inline void print(T x) {
  if (pt_out > buf_size - 32) flush();
  if (x < 0) {
    print('-');
    x = -x;
  }
  size_t digits = num_digits(x);
  int i;
  for (i = pt_out + digits - 4; i > (int)pt_out; i -= 4) {
    memcpy(buf_out + i, ptr.ptr + (x % 10000) * 4, 4);
    x /= 10000;
  }
  memcpy(buf_out + pt_out, ptr.ptr + x * 4 + (pt_out - i), 4 + i - pt_out);
  pt_out += digits;
}
template <class T>
inline void println(T x) {
  print(x);
  print('\n');
}
struct SetUp {
  SetUp() { load(); }
  ~SetUp() { flush(); }
} setup;
}  // namespace FastIO

using FastIO::print;
using FastIO::println;
using FastIO::scan;

constexpr int Nmax = 200001;
ll A[Nmax], acc[Nmax], maxs[Nmax];

int main() {
  int N;
  scan(N);
  REP(i, N) scan(A[i]);
  acc[0] = A[0];
  maxs[0] = max(0LL, A[0]);
  FOR(i, 1, N) {
    acc[i] = acc[i - 1] + A[i];
    maxs[i] = max(maxs[i - 1], acc[i]);
  }
  ll ans = 0, t = 0;
  REP(i, N) {
    chmax(ans, t + maxs[i]);
    t += acc[i];
  }
  println(ans);
  return 0;
}
#include<bits/stdc++.h>
using namespace std;
int main() {
        int64_t N; cin >> N;
        vector<int64_t> A(N), F(N, 0);
        int64_t curPos = 0, curMoves = 0, maxPos = 0;
        for (int64_t i = 0; i < N; ++i) {
            cin >> A[i];
            curMoves += A[i];
            F[i] = max((int64_t)0, curMoves);
            if (i) F[i] = max(F[i], F[i - 1]);
            maxPos = max(maxPos, curPos + F[i]);
            if (i) A[i] += A[i - 1];
            curPos += A[i];
        }
        cout << maxPos << endl;
    return 0;
}
