#include <bits/stdc++.h>
using namespace std;
inline int read() {
  char ch = getchar();
  int x = 0, f = 1;
  while (ch > '9' || ch < '0') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
const int maxn = 1e5 + 5;
long long f[maxn][3];
int n;
int main() {
  n = read();
  f[0][0] = 0, f[0][1] = f[0][2] = -0x3f3f3f;
  for (int i = 1, x; i <= n; ++i) {
    x = read();
    {
      f[i][0] = max(f[i - 1][0], f[i - 1][1]),
      f[i][1] = max(f[i - 1][1], f[i - 1][2]);
      f[i][2] = f[i - 1][2];
    }
    f[i][0] += x, f[i][1] -= x, f[i][2] += x;
    if (x < 0) f[i][2] = max(f[i][2], f[i][1]), f[i][1] = max(f[i][1], f[i][0]);
  }
  printf("%lld\n", max(f[n][0], max(f[n][1], f[n][2])));
  return 0;
}
