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