#include <bits/stdc++.h>
int a[112345], n, best, cur, total;
int main(void) {
  int i;
  scanf("%d", &n);
  cur = best = total = 0;
  for (i = 0; i < n; i++) scanf("%d", &a[i]), total += a[i];
  for (i = 0; i < n; i++) {
    cur += a[i];
    if (cur < 0)
      cur = 0;
    else if (best < cur)
      best = cur;
  }
  printf("%d\n", 2 * best - total);
  return 0;
}
