#include <bits/stdc++.h>
using namespace std;
const int maxn = 1000100;
long long n, a[maxn], pre[maxn], suf[maxn], sum, ans, s, mx;
int main() {
  while (~scanf("%lld", &n)) {
    for (long long i = 1; i <= n; i++) {
      scanf("%lld", &a[i]);
      sum += a[i];
    }
    for (long long i = 1; i <= n; i++) {
      if (s + a[i] < 0)
        s = 0;
      else {
        s += a[i];
        mx = max(mx, s);
      }
    }
    mx = max(mx, s);
    ans = mx * 2 - sum;
    printf("%lld\n", ans);
    sum = ans = s = mx = 0;
  }
  return 0;
}
