#include <bits/stdc++.h>
using namespace std;
class RMQ_ST {
 private:
  const static int RMQ_LOGMAX = 20;
  const static int RMQ_MAXN = 202000;
  vector<int> intLen;
  int M[RMQ_MAXN][RMQ_LOGMAX];

 public:
  vector<int> value;

 private:
  int N;
  inline int getIntLen(int key) {
    int len = 0;
    while (key > 0) {
      len++;
      key >>= 1;
    }
    return len;
  }

 public:
  RMQ_ST(int n) {
    N = n;
    intLen = vector<int>(N);
    value = vector<int>(N);
    for (int i = 0; i < N; ++i) intLen[i] = getIntLen(i);
  }
  inline void setValue(int posi, int value) { this->value[posi] = value; }
  void initRMQ() {
    for (int i = 0; i < N; ++i) M[i][0] = i;
    for (int j = 1; (1 << j) <= N; ++j) {
      int upper = N + 1 - (1 << j);
      int step = 1 << (j - 1);
      for (int i = 0; i < upper; ++i) {
        if (value[M[i][j - 1]] < value[M[i + step][j - 1]])
          M[i][j] = M[i][j - 1];
        else
          M[i][j] = M[i + step][j - 1];
      }
    }
  }
  int RMQ_value(int start, int stop) {
    int k = (stop - start + 1);
    k = intLen[k] - 1;
    return min(value[M[start][k]], value[M[stop - (1 << k) + 1][k]]);
  }
  int RMQ_posi(int start, int stop) {
    int k = (stop - start + 1);
    k = intLen[k] - 1;
    if (value[M[start][k]] <= value[M[stop - (1 << k) + 1][k]])
      return M[start][k];
    else
      return M[stop - (1 << k) + 1][k];
  }
};
int num[200000];
int N;
RMQ_ST leftSum(100002);
RMQ_ST rightSum(100002);
int totalSum;
int INFI = 2000000000;
void deal() {
  int ans = -INFI;
  for (int i = 1; i <= N; ++i) {
    if (num[i] >= 0) {
      int start = i;
      int stop = i;
      while (stop <= N && num[stop] >= 0) stop++;
      stop--;
      int midSum = leftSum.value[stop] - leftSum.value[start - 1];
      int leftMin = leftSum.RMQ_value(0, start - 1);
      int rightMin = rightSum.RMQ_value(stop + 1, N + 1);
      int nowSum = totalSum - 2 * leftMin - 2 * rightMin;
      ans = max(ans, nowSum);
      i = stop;
    }
  }
  int leftMin = leftSum.RMQ_value(0, N);
  ans = max(ans, totalSum - 2 * leftMin);
  cout << ans << endl;
}
void init() {
  totalSum = 0;
  scanf("%d", &N);
  for (int i = 1; i <= N; ++i) {
    scanf("%d", &num[i]);
    totalSum += num[i];
  }
  int sum = 0;
  leftSum.setValue(0, sum);
  for (int i = 1; i <= N; ++i) {
    sum += num[i];
    leftSum.setValue(i, sum);
  }
  sum = 0;
  rightSum.setValue(N + 1, 0);
  for (int i = N; i >= 1; --i) {
    sum += num[i];
    rightSum.setValue(i, sum);
  }
  leftSum.initRMQ();
  rightSum.initRMQ();
}
int main() {
  init();
  deal();
  return 0;
}

### Prompt

In cpp, your task is to solve the following problem:

Learn, learn and learn again — Valera has to do this every day. He is studying at mathematical school, where math is the main discipline. The mathematics teacher loves her discipline very much and tries to cultivate this love in children. That's why she always gives her students large and difficult homework. Despite that Valera is one of the best students, he failed to manage with the new homework. That's why he asks for your help. He has the following task. A sequence of n numbers is given. A prefix of a sequence is the part of the sequence (possibly empty), taken from the start of the sequence. A suffix of a sequence is the part of the sequence (possibly empty), taken from the end of the sequence. It is allowed to sequentially make two operations with the sequence. The first operation is to take some prefix of the sequence and multiply all numbers in this prefix by  - 1. The second operation is to take some suffix and multiply all numbers in it by  - 1. The chosen prefix and suffix may intersect. What is the maximum total sum of the sequence that can be obtained by applying the described operations?

Input

The first line contains integer n (1 ≤ n ≤ 105) — amount of elements in the sequence. The second line contains n integers ai ( - 104 ≤ ai ≤ 104) — the sequence itself.

Output

The first and the only line of the output should contain the answer to the problem.

Examples

Input

3
-1 -2 -3


Output

6


Input

5
-4 2 0 5 0


Output

11


Input

5
-1 10 -5 10 -2


Output

18

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
class RMQ_ST {
 private:
  const static int RMQ_LOGMAX = 20;
  const static int RMQ_MAXN = 202000;
  vector<int> intLen;
  int M[RMQ_MAXN][RMQ_LOGMAX];

 public:
  vector<int> value;

 private:
  int N;
  inline int getIntLen(int key) {
    int len = 0;
    while (key > 0) {
      len++;
      key >>= 1;
    }
    return len;
  }

 public:
  RMQ_ST(int n) {
    N = n;
    intLen = vector<int>(N);
    value = vector<int>(N);
    for (int i = 0; i < N; ++i) intLen[i] = getIntLen(i);
  }
  inline void setValue(int posi, int value) { this->value[posi] = value; }
  void initRMQ() {
    for (int i = 0; i < N; ++i) M[i][0] = i;
    for (int j = 1; (1 << j) <= N; ++j) {
      int upper = N + 1 - (1 << j);
      int step = 1 << (j - 1);
      for (int i = 0; i < upper; ++i) {
        if (value[M[i][j - 1]] < value[M[i + step][j - 1]])
          M[i][j] = M[i][j - 1];
        else
          M[i][j] = M[i + step][j - 1];
      }
    }
  }
  int RMQ_value(int start, int stop) {
    int k = (stop - start + 1);
    k = intLen[k] - 1;
    return min(value[M[start][k]], value[M[stop - (1 << k) + 1][k]]);
  }
  int RMQ_posi(int start, int stop) {
    int k = (stop - start + 1);
    k = intLen[k] - 1;
    if (value[M[start][k]] <= value[M[stop - (1 << k) + 1][k]])
      return M[start][k];
    else
      return M[stop - (1 << k) + 1][k];
  }
};
int num[200000];
int N;
RMQ_ST leftSum(100002);
RMQ_ST rightSum(100002);
int totalSum;
int INFI = 2000000000;
void deal() {
  int ans = -INFI;
  for (int i = 1; i <= N; ++i) {
    if (num[i] >= 0) {
      int start = i;
      int stop = i;
      while (stop <= N && num[stop] >= 0) stop++;
      stop--;
      int midSum = leftSum.value[stop] - leftSum.value[start - 1];
      int leftMin = leftSum.RMQ_value(0, start - 1);
      int rightMin = rightSum.RMQ_value(stop + 1, N + 1);
      int nowSum = totalSum - 2 * leftMin - 2 * rightMin;
      ans = max(ans, nowSum);
      i = stop;
    }
  }
  int leftMin = leftSum.RMQ_value(0, N);
  ans = max(ans, totalSum - 2 * leftMin);
  cout << ans << endl;
}
void init() {
  totalSum = 0;
  scanf("%d", &N);
  for (int i = 1; i <= N; ++i) {
    scanf("%d", &num[i]);
    totalSum += num[i];
  }
  int sum = 0;
  leftSum.setValue(0, sum);
  for (int i = 1; i <= N; ++i) {
    sum += num[i];
    leftSum.setValue(i, sum);
  }
  sum = 0;
  rightSum.setValue(N + 1, 0);
  for (int i = N; i >= 1; --i) {
    sum += num[i];
    rightSum.setValue(i, sum);
  }
  leftSum.initRMQ();
  rightSum.initRMQ();
}
int main() {
  init();
  deal();
  return 0;
}

```