#include <bits/stdc++.h>
using namespace std;
long long read() {
  long long nm = 0, fh = 1;
  long long cw = getchar();
  for (; !isdigit(cw); cw = getchar())
    if (cw == '-') fh = -fh;
  for (; isdigit(cw); cw = getchar()) nm = nm * 10 + (cw - '0');
  return nm * fh;
}
long long n, p[100020], G[100020], F[100020], ans;
int main() {
  n = read();
  for (long long i = 1; i <= n; i++) {
    p[i] = read();
    if (i > 1 && p[i] > 0 && p[i - 1] > 0) p[i - 1] += p[i], i--, n--;
  }
  for (long long i = 1; i <= n; i++)
    G[i] = G[i - 1] + p[i], F[i] = F[i - 1] + abs(p[i]);
  ans = G[n];
  for (long long i = 2; i <= n; i++)
    if (p[i - 1] < 0) {
      ans = max(ans, G[i - 1] - p[i] + F[n] - F[i]);
      break;
    }
  printf("%lld\n", ans);
  return 0;
}
