#include <bits/stdc++.h>
using namespace std;
const long long INF = -0x8080808080808080;
long long res[101111];
long long sum[101111];
long long s[101111];
long long A[101111];
long long R[101111];
long long L[101111];
inline long long prev(long long x) { return (x & (x - 1)); }
inline long long next(long long x) { return (x << 1) - (x & (x - 1)); }
void modify(long long pos, long long val) {
  if (val > A[pos]) {
    A[pos] = val;
    for (long long x = pos; x <= 101100; x = next(x)) L[x] = max(L[x], val);
    for (long long x = pos; x > 0; x = prev(x)) R[x] = max(R[x], val);
  }
}
long long findMax(long long b, long long e) {
  long long res = -INF;
  long long x;
  for (x = b; next(x) <= e; x = next(x)) {
    res = max(res, R[x]);
  }
  res = max(res, A[x]);
  for (x = e; prev(x) >= b; x = prev(x)) {
    res = max(res, L[x]);
  }
  return res;
}
int main() {
  long long n;
  cin >> n;
  for (long long i = 0; i < n; i++) {
    cin >> s[i];
  }
  long long summ = 0;
  long long rep = 0;
  for (long long i = 0; i < n; i++) {
    summ += s[i];
    rep -= s[i];
    res[i] = rep;
    sum[i] = summ;
  }
  memset(A, 0x80, sizeof A);
  memset(R, 0x80, sizeof R);
  memset(L, 0x80, sizeof L);
  rep = 0;
  modify(n + 1, sum[n - 1]);
  for (long long i = n - 1; i >= 0; i--) {
    rep -= s[i];
    modify(i + 1, rep + ((i == 0) ? 0 : sum[i - 1]));
  }
  long long mx = -INF;
  for (long long i = 0; i < n; i++) {
    long long cur = (i == 0) ? 0 : res[i - 1];
    long long plus = findMax(i + 1, n + 1) - ((i == 0) ? 0 : sum[i - 1]);
    cur += max(0ll, plus);
    if (cur > mx) mx = cur;
  }
  cout << mx << endl;
  return 0;
}
