#include <bits/stdc++.h>
const long long mod = 1e9 + 7;
const long long mod2 = 1e9;
using namespace std;
long long dp[100005];
long long a[1000005];
int main() {
  long long i, j, k;
  long long n, t = 0, maxn = 0, sum = 0;
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> a[i];
    sum += a[i];
    t += a[i];
    if (t < 0) t = 0;
    maxn = max(maxn, t);
  }
  cout << 2 * maxn - sum << endl;
}
