#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long int n;
  cin >> n;
  vector<long long int> x(n);
  for (__typeof((n)) i = (0); i < (n); i += 1) cin >> x[i];
  long long int suma = accumulate((x).begin(), (x).end(), 0LL);
  vector<long long int> y(n + 1);
  vector<long long int> z(n + 1);
  partial_sum((x).begin(), (x).end(), y.begin() + 1);
  z[n] = 0;
  for (int i = n - 1; i >= 0; i--) {
    z[i] = x[i] + z[i + 1];
  }
  for (__typeof((n + 1)) i = (1); i < (n + 1); i += 1) {
    y[i] = min(y[i], y[i - 1]);
  }
  for (int i = n - 1; i >= 0; i--) {
    z[i] = min(z[i], z[i + 1]);
  }
  int maxpos = 0;
  for (int i = 1; i <= n; i++) {
    maxpos = min((long long int)maxpos, y[i] + z[i]);
  }
  cout << suma - 2 * maxpos;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
