#include <bits/stdc++.h>
using namespace std;
int s[100000];
int bestgb[100000], bestge[100000];
int main() {
  int n;
  cin >> n;
  int total = 0;
  for (int i = 0; i < n; i++) {
    cin >> s[i];
    total += s[i];
  }
  int sum = 0, sumn = 0, bestg = 0;
  for (int i = 0; i < n; i++) {
    sum += s[i];
    sumn -= s[i];
    bestg = max(bestg, sumn - sum);
    bestgb[i] = bestg;
  }
  sum = 0, sumn = 0, bestg = 0;
  for (int i = n - 1; i >= 0; i--) {
    sum += s[i];
    sumn -= s[i];
    bestg = max(bestg, sumn - sum);
    bestge[i] = bestg;
  }
  int best = max(total + bestgb[n - 1], total + bestge[0]);
  for (int k = 0; k < n - 1; k++) {
    best = max(best, total + bestgb[k] + bestge[k + 1]);
  }
  cout << best << "\n";
}
