#include <bits/stdc++.h>
using namespace std;
const double PI = 3.14159265358979;
const double PI2 = 6.28318530717958;
const double PId2 = 1.570796326794895;
template <typename T>
T sqr(T x) {
  return x * x;
}
template <typename T>
T gcd(T a, T b) {
  return (b ? gcd(b, a % b) : a);
}
long long pw(long long a, long long p, int mod) {
  long long res = 1;
  while (p) {
    if (p & 1) {
      --p;
      res = (res * a) % mod;
    } else {
      p >>= 1;
      a = (a * a) % mod;
    }
  }
  return res;
}
inline vector<int> ReadVI(int count) {
  vector<int> arrayname(count);
  for (int i = 0; i < count; i++) cin >> arrayname[i];
  return arrayname;
}
inline vector<long long> ReadVlong(int count) {
  vector<long long> arrayname(count);
  for (int i = 0; i < count; i++) cin >> arrayname[i];
  return arrayname;
}
const int MOD = 1000000007;
const int MAXVALUE = 100001;
vector<int> F(const vector<int>& a) {
  vector<pair<int, int> > temp(a.size());
  for (int i = 0; i < a.size(); i++) {
    temp[i].first = a[i];
    temp[i].second = i;
  }
  sort(temp.rbegin(), temp.rend());
  vector<int> res;
  int i = 0;
  int n = -1;
  while (i < temp.size()) {
    int z = temp[i].first;
    if (temp[i].second > n) {
      res.push_back(temp[i].second);
      n = temp[i].second;
    }
    while (i + 1 < temp.size() && temp[i + 1].first == z) i++;
    i++;
  }
  return res;
}
int FindMax(const vector<int>& a, int l, int r) {
  int ans = a[l];
  for (int i = l; i <= r; i++) ans = max(ans, a[i]);
  return ans;
}
int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  vector<int> pref(n + 1), suff(n + 1);
  int sum = 0;
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
    sum += a[i];
  }
  pref[0] = 0, suff[n] = 0;
  for (int i = 1; i <= n; i++)
    pref[i] = pref[i - 1] + (a[i - 1] < 0 ? 1 : -1) * 2 * abs(a[i - 1]);
  for (int i = n - 1; i >= 0; i--)
    suff[i] = suff[i + 1] + (a[i] < 0 ? 1 : -1) * 2 * abs(a[i]);
  vector<int> numb = F(suff);
  int l = 0;
  int ans = INT_MIN;
  for (int i = 0; i < numb.size(); i++) {
    int t = FindMax(pref, l, numb[i]);
    ans = max(ans, sum + t + suff[numb[i]]);
    l = numb[i] + 1;
  }
  cout << ans;
  return 0;
}
