#include <bits/stdc++.h>
using namespace std;
namespace yspm {
inline long long read() {
  long long res = 0, f = 1;
  char k;
  while (!isdigit(k = getchar()))
    if (k == '-') f = -1;
  while (isdigit(k)) res = res * 10 + k - '0', k = getchar();
  return res * f;
}
const long long N = 1e5 + 10;
long long n, T, a[N], dp[N][5];
inline void work() {
  memset(a, 0, sizeof(a));
  memset(dp, 0, sizeof(dp));
  n = read();
  for (long long i = 1; i <= n; ++i) a[i] = read();
  for (long long i = 1; i <= n; ++i) {
    dp[i][0] = max(dp[i - 1][0], dp[i - 1][1]) + a[i];
    dp[i][1] = dp[i - 1][1] - a[i];
    dp[i][2] = max(dp[i - 1][0], max(dp[i - 1][2], dp[i - 1][3])) - a[i];
    dp[i][3] = max(dp[i - 1][0], max(dp[i - 1][1], dp[i - 1][3])) + a[i];
  }
  printf("%lld\n", max(dp[n][0], max(dp[n][1], max(dp[n][2], dp[n][3]))));
  return;
}
signed main() {
  work();
  return 0;
}
}  // namespace yspm
signed main() {
  yspm::main();
  return 0;
}
