#include <bits/stdc++.h>
using namespace std;
int N, num[200000], suml[200000], sumr[200000];
int minl[200000], minr[200000];
void get_data() {
  scanf("%d", &N);
  int i;
  for (i = 0; i < N; i++) scanf("%d", &num[i]);
}
int f_max(int x, int y) { return x > y ? x : y; }
void run() {
  int i;
  suml[0] = num[0];
  for (i = 1; i < N; i++) suml[i] = num[i] + suml[i - 1];
  for (i = 0; i < N; i++) sumr[i] = suml[N - 1] - suml[i] + num[i];
  int vmin, temp;
  minl[0] = vmin = temp = num[0];
  for (i = 1; i < N; i++) {
    temp += num[i];
    if (temp < vmin) vmin = temp;
    minl[i] = vmin;
  }
  minr[N - 1] = vmin = temp = num[N - 1];
  for (i = N - 2; i >= 0; i--) {
    temp += num[i];
    if (temp < vmin) vmin = temp;
    minr[i] = vmin;
  }
  int sum = sumr[0], vmax, vl, vr;
  vmax = 0;
  vmax = f_max(vmax, -minr[0]);
  vmax = f_max(vmax, -minl[N - 1]);
  for (i = 0; i < N - 1; i++) {
    vl = f_max(-minl[i], 0);
    vr = f_max(-minr[i + 1], 0);
    temp = vl + vr;
    vmax = f_max(temp, vmax);
  }
  printf("%d\n", vmax * 2 + sum);
}
int main() {
  get_data();
  run();
  return 0;
}
