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;
string to_string(string s) { return '"' + s + '"'; }
string to_string(char s) { return string(1, s); }
string to_string(const char* s) { return to_string((string)s); }
string to_string(bool b) { return (b ? "true" : "false"); }
template <typename A>
string to_string(A);
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename A>
string to_string(A v) {
  bool f = 1;
  string r = "{";
  for (const auto& x : v) {
    if (!f) r += ", ";
    f = 0;
    r += to_string(x);
  }
  return r + "}";
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
const int inf = 1e9;
const long long INF = 1e18;
const int mod = 1e9 + 7;
const int bit32 = log2(inf) + 3;
const int bit64 = log2(INF) + 3;
inline int add(long long a, long long b) {
  a += b;
  if (a >= mod) a -= mod;
  return a;
}
inline int sub(long long a, long long b) {
  a -= b;
  if (a < 0) a += mod;
  return a;
}
inline int mul(long long a, long long b) {
  a %= mod;
  b %= mod;
  return (int)((long long)a * b % mod);
}
inline int modexpo(long long a, long long b) {
  int res = 1;
  while (b > 0) {
    if (b & 1) res = mul(res, a);
    a = mul(a, a);
    b /= 2;
  }
  return res;
}
inline int divide(long long a, long long b) {
  return mul(a, modexpo(b, mod - 2));
}
inline int inv(long long a) { return modexpo(a, mod - 2); }
clock_t time_p = clock();
void ktj() {
  time_p = clock() - time_p;
  cerr << "Time elapsed : " << (float)(time_p) / CLOCKS_PER_SEC << "\n";
}
void pre() {}
const int N = 1e5 + 5;
int a[N];
int n;
int Kadane(int val) {
  int i, j, ans = val;
  bool done = 0;
  for (i = 1; i <= n; i++) {
    int l = i, r = i;
    bool found = 0;
    while (i <= n and a[i] <= val) {
      if (a[i] == val) {
        found = 1;
        done = 1;
      }
      i += 1;
    }
    r = i - 1;
    if (l <= r and found) {
      int res, curr;
      res = curr = a[l];
      for (j = l + 1; j <= r; j++) {
        curr = max(curr + a[j], a[j]);
        res = max(res, curr);
      }
      ans = max(ans, res);
    }
  }
  if (done) {
    ans -= val;
  } else
    ans = 0;
  return max(ans, 0);
}
void solve() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  int ans = 0;
  for (int i = -30; i <= 30; i++) {
    ans = max(ans, Kadane(i));
  }
  cout << ans << '\n';
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  pre();
  int t = 1, T;
  if (0) cin >> t;
  for (T = 1; T <= t; T++) {
    if (0) cout << "Case #" << T << ": ";
    solve();
  }
  ktj();
}
