#include <bits/stdc++.h>
using namespace std;
const long long INF = (1LL << 60);
int N;
long long v[100005];
long long dp[100005][4];
int gint() {
  char ch = getchar();
  int sgn = 1;
  while (ch < '0' || '9' < ch) {
    if (ch == '-') sgn = -1;
    ch = getchar();
  }
  int x = 0;
  while ('0' <= ch && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  x *= sgn;
  return x;
}
int main() {
  N = gint();
  for (int i = 1; i <= N; i++) v[i] = gint();
  dp[0][0] = 0, dp[0][1] = dp[0][2] = dp[0][3] = -INF;
  for (int i = 1; i <= N + 1; i++) {
    dp[i][0] =
        max(max(dp[i - 1][0], dp[i - 1][1]), max(dp[i - 1][2], dp[i - 1][3])) +
        v[i];
    dp[i][1] = max(dp[i - 1][1], max(dp[i - 1][2], dp[i - 1][3])) - v[i];
    dp[i][2] = max(dp[i - 1][2], dp[i - 1][3]) + v[i];
    dp[i][3] = dp[i - 1][3] - v[i];
    if (v[i] > 0) continue;
    dp[i][1] = max(dp[i][1], dp[i - 1][0] + v[i]);
    dp[i][2] = max(dp[i][2], dp[i - 1][1] - v[i]);
    dp[i][3] = max(dp[i][3], dp[i - 1][2] + v[i]);
  }
  printf("%lld\n", dp[N + 1][0]);
  return 0;
}
