#include <bits/stdc++.h>
long long s, tot, ans, a, n;
long long Max(long long p, long long q) { return p > q ? p : q; }
void fr(long long &num) {
  num = 0;
  char c = getchar();
  int p = 1;
  while (c < '0' || c > '9') c == '-' ? p = -1, c = getchar() : c = getchar();
  while (c >= '0' && c <= '9') num = num * 10 + c - '0', c = getchar();
  num *= p;
}
int main() {
  fr(n);
  while (n--) fr(a), s = Max(s + a, 0), ans = Max(ans, s), tot += a;
  printf("%lld", 2 * ans - tot);
  return 0;
}
