#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; ++i)
#define PI = 3.14159265359
#define INF 100100100
#define mod 10000007
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Graph = vector<vector<int>>;

int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i,n) cin >> a[i];
  int ans = 0;
  rep(l,n){
    int x = INF;
    for(int r = l; r < n; ++r){
      x = min(x, a[r]);
      ans = max(ans, (r-l+1)*x);
    }
  }
  cout << ans << endl;
  return 0;
}

#include <bits/stdc++.h>
#define rep(i,N) for(int i=0; i<(N); i++)
using namespace std;

int main() {
  int N;
  cin >> N;
  vector<int64_t> a(N);
  rep(i,N) cin >> a.at(i);
  
  int64_t ans=0;
  rep(i,N){
    if(i != 0){
      if(a.at(i) == a.at(i-1)) continue;
    }
    int64_t now=0;
    for(int j=i-1; 0<=j; j--){
      if(a.at(i) <= a.at(j)) now += a.at(i);
      else break;
    }
    for(int j=i+1; j<N; j++){
      if(a.at(i) <= a.at(j)) now += a.at(i);
      else break;
    }
    now += a.at(i);
    ans = max(ans,now);
  }
  
  cout << ans << endl;
}