#include #include #include #include using namespace std; using ll = long long; constexpr ll INF = 1LL << 62; int main() { int n; cin >> n; vector a(n); for (int i = 0; i < n; ++i) cin >> a[i]; assert(1 <= n && n <= 200000); for (int i = 0; i < n; ++i) assert(abs(a[i]) <= 1000'000'000); vector> dp(n+1, vector(3, -INF)); dp[0][0] = 0; for (int i = 0; i < n; ++i) { dp[i+1][0] = max(dp[i][0], -(ll)a[i]); dp[i+1][1] = max({dp[i][1], dp[i][2] - a[i], dp[i][0] - a[i]}); dp[i+1][2] = max(dp[i][2], dp[i][1] + a[i]); } cout << max(dp[n][1], dp[n][2]) << endl; }