#include <bits/stdc++.h>
using namespace std;
int n, m, t;
long long dp[2][4] = {0};
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &t);
    dp[1][0] = dp[0][0] + t;
    dp[1][1] = dp[0][1] - t;
    dp[1][2] = max(dp[0][1] + t, dp[0][2] + t);
    dp[1][3] = max(dp[0][2] - t, dp[0][3] - t);
    for (int i = 0; i < 4; i++) {
      dp[0][i] = dp[1][i];
    }
  }
  long long ans = dp[0][0];
  for (int i = 1; i < 4; i++) {
    ans = max(ans, dp[0][i]);
  }
  cout << ans;
  return 0;
}
