#include <bits/stdc++.h>
using namespace std;
template <class t>
t lcm(t a, t b) {
  return ((a * b) / __gcd(a, b));
}
const long long maxn = 1e6;
long long segtree1[maxn], segtree2[maxn];
long long preinv[maxn], postinv[maxn];
void buildtree(long long cur, long long l, long long r, long long tree[],
               long long ip[]) {
  if (l == r) {
    tree[cur] = ip[l];
    return;
  }
  long long mid = (l + r) / 2;
  long long lc = 2 * cur, rc = 2 * cur + 1;
  buildtree(lc, l, mid, tree, ip);
  buildtree(rc, mid + 1, r, tree, ip);
  tree[cur] = max(tree[lc], tree[rc]);
}
long long querytree(long long cur, long long l, long long r, long long qx,
                    long long qy, long long tree[]) {
  if (l > qy || r < qx) return 0;
  if (l >= qx && r <= qy) return tree[cur];
  long long mid = (l + r) / 2;
  long long lc = 2 * cur, rc = 2 * cur + 1;
  return max(querytree(lc, l, mid, qx, qy, tree),
             querytree(rc, mid + 1, r, qx, qy, tree));
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  long long sum = 0, temp = 0, n, ans;
  cin >> n;
  for (long long i = 1; i <= n; i++) {
    cin >> temp;
    sum += temp;
    preinv[i] = preinv[i - 1] - temp;
    postinv[i] = -temp;
  }
  ans = sum;
  for (long long i = n; i >= 0; i--) postinv[i] += postinv[i + 1];
  buildtree(1, 0, n, segtree1, preinv);
  buildtree(1, 0, n, segtree2, postinv);
  for (long long i = 0; i <= n; i++) {
    long long min1 = max(0LL, querytree(1, 0, n, 0, i, segtree1));
    long long min2 = max(0LL, querytree(1, 0, n, i + 1, n, segtree2));
    temp = sum + 2 * (min1 + min2);
    ans = max(ans, temp);
  }
  cout << ans;
  return 0;
}
