#include <bits/stdc++.h>
using namespace std;
const int N = 2e6 + 5, Mod = 1e9 + 7, MAXN = 3e5 + 10, LG = 20, M = 1e9,
          P = 727, Sq = 445 + 5;
const long long inf = 3e18 + 10;
int n, ans = -Mod, dp[N], pd[N], a[N];
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> a[i];
  int sum = 0;
  dp[0] = 0;
  for (int i = 1; i <= n; i++) {
    sum += a[i];
    dp[i] = max(dp[i - 1], -2 * sum);
  }
  pd[n + 1] = 0;
  sum = 0;
  for (int i = n; i >= 1; i--) {
    sum += a[i];
    pd[i] = max(pd[i + 1], -2 * sum);
  }
  for (int i = 1; i <= n; i++)
    ans = max(ans, max(dp[i - 1] + pd[i], dp[i] + pd[i + 1]));
  return cout << ans + sum, 0;
}
