#include <bits/stdc++.h>
using namespace std;
int ar[100005];
int suml[100005];
int sumr[100005];
int sums[100005];
int main() {
  int n;
  scanf("%d", &n);
  int sumA = 0;
  int Answ = 0;
  for (int i = 0; i < n; i++) {
    scanf("%d", &ar[i]);
    sumA += ar[i];
    sums[i] = sumA;
  }
  Answ = max(Answ, sumA);
  int cursum = 0;
  int curminsum = 0;
  int curmaxsum = 0;
  for (int i = 0; i < n; i++) {
    cursum += ar[i];
    if (-cursum > curmaxsum) curmaxsum = -cursum;
    suml[i] = curmaxsum;
  }
  curmaxsum = 0;
  cursum = 0;
  for (int i = n - 1; i >= 0; i--) {
    cursum += ar[i];
    if (-cursum > curmaxsum) curmaxsum = -cursum;
    sumr[i] = curmaxsum;
  }
  sumr[n] = 0;
  for (int i = 0; i < n; i++) {
    if (2 * suml[i] + sumA > Answ) Answ = 2 * suml[i] + sumA;
    int j = n - 1 - i;
    if (2 * sumr[j] + sumA > Answ) Answ = 2 * sumr[j] + sumA;
    if (2 * suml[i] + 2 * sumr[i + 1] + sumA > Answ)
      Answ = 2 * suml[i] + 2 * sumr[i + 1] + sumA;
  }
  printf("%d\n", Answ);
}
