#include <bits/stdc++.h>
using namespace std;
int main() {
  int ma = 0, last = 0, x, n, ans = 0, sum = 0;
  cin >> n;
  while (n--) {
    cin >> x;
    sum += x;
    ma = max(ma, x + last);
    if (x + last > 0)
      last += x;
    else
      last = 0;
  }
  cout << 2 * ma - sum;
  return 0;
}
