#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> v(n);
  for (int _n((n)-1), i(0); i <= _n; i++) scanf("%d", &v[i]);
  vector<int> q1(n);
  vector<int> q2(n);
  vector<int> s1(n);
  vector<int> s2(n);
  vector<int> p1(n);
  vector<int> p2(n);
  s1[0] = v[0];
  s2[n - 1] = v[n - 1];
  for (int i = 1; i < n; i++) s1[i] = s1[i - 1] + v[i];
  for (int i = n - 2; i >= 0; i--) s2[i] = s2[i + 1] + v[i];
  for (int i = 0; i < n; i++) q1[i] = s1[i] < 0 ? -2 * s1[i] : 0;
  for (int i = n - 1; i >= 0; i--) q2[i] = s2[i] < 0 ? -2 * s2[i] : 0;
  p1[0] = q1[0];
  p2[n - 1] = q2[n - 1];
  for (int i = 1; i < n; i++) p1[i] = max(p1[i - 1], q1[i]);
  for (int i = n - 2; i >= 0; i--) p2[i] = max(p2[i + 1], q2[i]);
  int res = max(s1[n - 1], -s1[n - 1]) - s1[n - 1];
  for (int _n((n - 1) - 1), i(0); i <= _n; i++)
    res = max(res, p1[i] + p2[i + 1]);
  cout << res + s1[n - 1] << endl;
  return 0;
}
