#include <bits/stdc++.h>
using namespace std;
int const maxn = 100000;
vector<vector<int> > adj;
bitset<10000> bs;
vector<int> primes;
void sieve() {
  bs.set();
  bs[0] = bs[1] = 0;
  for (long long i = 2; i < 10000; i++)
    if (bs[i]) {
      for (long long j = i * i; j < 10000; j += i) bs[j] = 0;
      primes.push_back(i);
    }
}
map<int, int> m1, m2;
long long a[maxn], b[maxn];
void pf(long long N) {
  int id = 0;
  long long ff = primes[id];
  while (ff * ff <= N && ff <= sqrt(1. * N + 3)) {
    while (N % ff == 0) {
      N /= ff;
      m1[ff]++;
    }
    ff = primes[++id];
  }
  if (N != 1) m1[N]++;
}
void pff(long long N) {
  int id = 0;
  long long ff = primes[id];
  while (ff * ff <= N && ff <= sqrt(1. * N + 3)) {
    while (N % ff == 0) {
      N /= ff;
      m2[ff]++;
    }
    ff = primes[++id];
  }
  if (N != 1) m2[N]++;
}
int r[5010][5010], l[5010][5010];
int main() {
  int n;
  cin >> n;
  long long sum = 0;
  long long cnt = 0;
  long long t = 0;
  while (n--) {
    int x;
    cin >> x;
    t += x;
    cnt = max(cnt, t);
    t = max(t, (long long)0);
    sum += x;
  }
  cout << 2 * cnt - sum << endl;
}
