#include <iostream>
#include <queue>
using namespace std;
using ll = long long;

int n;
priority_queue<ll> q;

void solve()
{
    q.push(0);
    ll res = 1, before = q.top(), now;
    q.pop();
    while (q.size() > 0)
    {
        now = q.top();
        q.pop();
        if (before > now)
        {
            res = res * (before - now + 1) % (1000000007);
            before = now;
        }
    }
    cout << res << '\n';
}

int main()
{
    ll qtemp;
    cin >> n;
    for (int i=0; i<n; i++)
    {
        cin >> qtemp;
        q.push(qtemp);
    }

    solve();

    return 0;
}

/*pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")*/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; i++)
#define RFOR(i, a, n) for (ll i = (ll)n - 1; i >= (ll)a; i--)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) RFOR(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define bra(first, second) '(' << first << ',' << second << ')'
//constexpr ll MOD = 1000000007;
constexpr ll MOD = 998244353;
ll INF = 1001001001001001001;
long double EPS = 1e-7;
long double PI = 3.141592653589793238;
template <typename T>
void remove(std::vector<T> &vector, unsigned int index)
{
   vector.erase(vector.begin() + index);
}

using Graph = vector<vector<ll>>;

// MOD確認

ll N;
ll A[10010];
ll B[10010];
ll C[10010];

int main(){
  cin >> N;
  rep(i,N) cin >> A[i];
  rep(i,N){
    FOR(j,i,N){
      if(A[i] <= A[j]) B[i]++;
      else break;
    }
    RFOR(j,0,i){
      if(A[i] <= A[j]) C[i]++;
      else break;
    }
  }
  ll ans = 0;
  rep(i,N){
    ans = max(ans,A[i] * (B[i] + C[i]));
  }
  cout << ans << endl;
}
