Alice and Bob are playing yet another card game. This time the rules are the following. There are n cards lying in a row in front of them. The i-th card has value a_i. 

First, Alice chooses a non-empty consecutive segment of cards [l; r] (l ≤ r). After that Bob removes a single card j from that segment (l ≤ j ≤ r). The score of the game is the total value of the remaining cards on the segment (a_l + a_{l + 1} + ... + a_{j - 1} + a_{j + 1} + ... + a_{r - 1} + a_r). In particular, if Alice chooses a segment with just one element, then the score after Bob removes the only card is 0.

Alice wants to make the score as big as possible. Bob takes such a card that the score is as small as possible.

What segment should Alice choose so that the score is maximum possible? Output the maximum score.

Input

The first line contains a single integer n (1 ≤ n ≤ 10^5) — the number of cards.

The second line contains n integers a_1, a_2, ..., a_n (-30 ≤ a_i ≤ 30) — the values on the cards.

Output

Print a single integer — the final score of the game.

Examples

Input


5
5 -2 10 -1 4


Output


6


Input


8
5 2 5 3 -30 -30 6 9


Output


10


Input


3
-10 6 -15


Output


0

Note

In the first example Alice chooses a segment [1;5] — the entire row of cards. Bob removes card 3 with the value 10 from the segment. Thus, the final score is 5 + (-2) + (-1) + 4 = 6.

In the second example Alice chooses a segment [1;4], so that Bob removes either card 1 or 3 with the value 5, making the answer 5 + 2 + 3 = 10.

In the third example Alice can choose any of the segments of length 1: [1;1], [2;2] or [3;3]. Bob removes the only card, so the score is 0. If Alice chooses some other segment then the answer will be less than 0.
#include <bits/stdc++.h>
using namespace std;
template <class T>
void _R(T &x) {
  cin >> x;
}
void _R(int &x) { scanf("%d", &x); }
void _R(long long &x) { scanf("%lld", &x); }
void _R(unsigned long long &x) { scanf("%llu", &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template <class T, class... U>
void R(T &head, U &...tail) {
  _R(head);
  R(tail...);
}
template <class T>
void _W(const T &x) {
  cout << x;
}
void _W(const int &x) { printf("%d", x); }
void _W(const long long &x) { printf("%lld", x); }
void _W(const double &x) { printf("%.16f", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
void _W(const unsigned long long &x) { printf("%llu", x); }
template <class T, class U>
void _W(const pair<T, U> &x) {
  _W(x.first);
  putchar(' ');
  _W(x.second);
}
template <class T>
void _W(const vector<T> &x) {
  for (auto i = x.begin(); i != x.end(); _W(*i++))
    if (i != x.cbegin()) putchar(' ');
}
void W() {}
template <class T, class... U>
void W(const T &head, const U &...tail) {
  _W(head);
  putchar(sizeof...(tail) ? ' ' : '\n');
  W(tail...);
}
const int MOD = 1e9 + 7, mod = 998244353;
long long qpow(long long a, long long b) {
  long long res = 1;
  a %= MOD;
  assert(b >= 0);
  for (; b; b >>= 1) {
    if (b & 1) res = res * a % MOD;
    a = a * a % MOD;
  }
  return res;
}
const int MAXN = 2e5 + 10, MAXM = 2e6 + 10;
const int INF = INT_MAX, SINF = 0x3f3f3f3f;
const long long llINF = LLONG_MAX, SLINF = 0x3f3f3f3f3f3f3f3fLL;
const int inv2 = (MOD + 1) / 2;
const int Lim = 1 << 20;
long long a[MAXN], b[MAXN], pre[MAXN], suf[MAXN];
long long calc(int l, int r, int p) {
  long long sum = 0, ans = -INF;
  for (int i = l - 1; i <= r + 1; i++) pre[i] = suf[i] = 0;
  for (int i = l; i <= r; i++) pre[i] = a[i] + pre[i - 1], sum += a[i];
  for (int i = r; i >= l; i--) suf[i] = a[i] + suf[i + 1];
  pre[r + 1] = -INF;
  suf[l - 1] = -INF;
  for (int i = r; i >= l; i--) pre[i] = max(pre[i], pre[i + 1]);
  for (int i = l; i <= r; i++) suf[i] = max(suf[i], suf[i - 1]);
  for (int i = l; i <= r; i++)
    if (a[i] == p) {
      ans = max(ans, suf[i] + pre[i] - sum);
    }
  return ans;
}
void solve() {
  int n;
  R(n);
  long long ans = 0;
  for (int i = 1; i <= n; i++) {
    R(a[i]);
  }
  a[n + 1] = 880;
  for (int i = 30; i >= -30; i--) {
    int lst = 0;
    for (int j = 1; j <= n + 1; j++)
      if (a[j] > i) ans = max(ans, calc(lst + 1, j - 1, i) - i), lst = j;
  }
  W(ans);
}
int main() {
  int T = 1;
  while (T--) solve();
  return 0;
}
