#include <bits/stdc++.h>
using namespace std;
inline long long int gcd(long long int a, long long int b) {
  long long int t;
  while (b) {
    a = a % b;
    t = a;
    a = b;
    b = t;
  }
  return a;
}
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  vector<long long int> v1;
  long long int n;
  cin >> n;
  long long int sum = 0;
  for (long long int i = 0; i < n; i++) {
    long long int x;
    cin >> x;
    v1.push_back(x);
    sum += x;
  }
  long long int curr = 0;
  long long int ans = 0;
  for (long long int i = 0; i < n; i++) {
    curr += v1[i];
    if (curr < 0) {
      curr = 0;
    }
    ans = max(ans, curr);
  }
  cout << sum * -1 + 2 * ans << endl;
  ;
  return 0;
}
