#include <bits/stdc++.h>
using namespace std;
void DBG() { cerr << "]\n"; }
template <typename T, typename... Args>
void DBG(T first, Args... args) {
  cerr << first;
  if (sizeof...(args)) cerr << ", ";
  DBG(args...);
}
const long long N = 1e5 + 10;
vector<long long> pref(N);
long long sum(long long l, long long r) {
  if (l < 0 || r < 0 || l > r) return 0;
  return pref[r] - (l - 1 >= 0 ? pref[l - 1] : 0);
}
void solve() {
  long long n;
  cin >> n;
  vector<long long> a(n);
  for (long long i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (long long i = 0; i < n; i++) {
    pref[i] = (i - 1 >= 0 ? pref[i - 1] : 0) + a[i];
  }
  long long s = 0;
  long long max_sum = 0;
  for (long long i = 0; i < n; i++) {
    if (s + a[i] > 0) {
      s += a[i];
    } else {
      s = 0;
    }
    max_sum = max(max_sum, s);
  }
  cout << 2 * max_sum - sum(0, n - 1) << '\n';
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  long long t = 1;
  for (long long tt = 1; tt <= t; tt++) {
    solve();
  }
}
