#include <bits/stdc++.h>
using namespace std;
void all_input() {}
int main() {
  all_input();
  int n;
  cin >> n;
  int a[n];
  for (int i = 0; i < n; i += 1) cin >> a[i];
  vector<int> pre(n, 0), aage(n, 0), piche(n, 0);
  for (int i = 0; i < n; i += 1) {
    if (i == 0) {
      pre[i] = a[i];
      aage[i] = -a[i];
      piche[n - 1] = -a[n - 1];
    } else {
      pre[i] = pre[i - 1] + a[i];
      aage[i] = aage[i - 1] - a[i];
      piche[n - 1 - i] = piche[n - i] - a[n - 1 - i];
    }
  }
  vector<int> maxi(n, 0);
  int maxm = INT_MIN, idx;
  for (int i = n - 1; i >= 0; i--) {
    if (piche[i] >= maxm) {
      maxm = piche[i];
      idx = i;
    }
    maxi[i] = idx;
  }
  int ans = INT_MIN;
  for (int i = 0; i < n; i++) {
    int l = aage[i];
    int r = (i == n - 1) ? 0 : piche[maxi[i + 1]];
    int mid = (i == n - 1) ? 0 : pre[maxi[i + 1] - 1] - pre[i];
    if (r <= 0) {
      mid = max(mid, pre[n - 1] - pre[i]);
      r = 0;
    }
    ans = max(ans, l + r + mid);
  }
  int x = (maxi[0] == 0) ? 0 : pre[maxi[0] - 1];
  ans = max(ans, piche[maxi[0]] + x);
  ans = max(ans, aage[n - 1]);
  ans = max(ans, piche[0]);
  ans = max(ans, pre[n - 1]);
  cout << ans;
  return 0;
}
