#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<long long> a(n);
  for (int i = 0; i < n; i++) cin >> a[i];
  vector<vector<long long>> dp1(n, vector<long long>(2));
  dp1[0][0] = a[0];
  dp1[0][1] = -a[0];
  for (int i = 1; i < n; i++) {
    dp1[i][0] = max(a[i] + dp1[i - 1][0], a[i] + dp1[i - 1][1]);
    dp1[i][1] = -a[i] + dp1[i - 1][1];
  }
  vector<vector<long long>> dp2(n, vector<long long>(2));
  dp2[n - 1][0] = a[n - 1];
  dp2[n - 1][1] = -a[n - 1];
  for (int i = n - 2; i >= 0; i--) {
    dp2[i][0] = max(a[i] + dp2[i + 1][0], a[i] + dp2[i + 1][1]);
    dp2[i][1] = -a[i] + dp2[i + 1][1];
  }
  long long res = max(dp1[n - 1][0], dp1[n - 1][1]);
  for (int i = 0; i < n - 1; i++) {
    res =
        max(res, max(dp1[i][0], dp1[i][1]) + max(dp2[i + 1][0], dp2[i + 1][1]));
  }
  cout << res << '\n';
  return 0;
}
