#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e15 + 15;
const int MOD = 1e9 + 7;
int main() {
  cin.tie(0);
  cout.tie(0);
  cin.sync_with_stdio(false);
  long long n, temp, i, msum = 0, sum = 0, csum = 0;
  vector<long long> v;
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> temp;
    v.push_back(temp);
    sum += temp;
  }
  for (i = 0; i < n; i++) {
    csum += v[i];
    if (csum < 0) csum = 0;
    msum = max(msum, csum);
  }
  cout << 2 * msum - sum;
  return 0;
}
