#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
#define int long long int
#define watch(x) cout << (#x) << " is " << (x) << "\n"
#define watch2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << "\n"
#define INF LLONG_MAX


template<typename ... T> 
void print(const T& ... t)
{
  initializer_list<int>{ (std::cout << t << " ", 0)... };
  cout  << "\n";
}
template <typename T, size_t SIZE>
inline void zero(T(&arr)[SIZE])
{
    memset(arr, 0, SIZE * sizeof(T));
}


void readFile()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    #ifndef ONLINE_JUDGE
    time_t ttt ; 
    struct tm *tmptmptmp ; 
    char MY_TIME[50]; 
    time( &ttt ); 
    tmptmptmp = localtime( &ttt ); 
    strftime(MY_TIME, sizeof(MY_TIME), "%I:%M:%S %p", tmptmptmp);
 
 
    print("-----------");
    print(MY_TIME);
    print("-----------");
    #endif
}

void smallestLeftandRight(vector<int> &input, vector<int> &left, vector<int> &right)
{
    int sz = input.size();
    left.resize(sz);
    right.resize(sz);
    input.insert(input.begin(), 1, -INF);
    input.push_back(-INF);
    

    stack<int> s;
    stack<int> pos;
    int idx = -1;
    
    for(auto val : input)
    {
        if(pos.empty())
        {
            s.push(val);
            pos.push(idx);
            ++idx;
            continue;
        }

        while(!s.empty() and s.top() > val)
        {
            s.pop();
            if(pos.top() != -1)
            {
                right[pos.top()] = idx;
            }
            pos.pop();
        }


        if(s.top() == val)
        {
            if(pos.top() != -1)
            {
                left[idx] = left[pos.top()];
            }
        }

        else
        {
            left[idx] = pos.top();    
        }
        s.push(val);
        pos.push(idx);    

        ++idx;
    }

}

int maxAreaHistogram(vector<int> &input, vector<int> &left, vector<int> &right)
{
    //Note: We have manipulated the original input array;
    int maxArea = 0;
    for(int idx = 0; idx < left.size(); ++idx)
    {
        int area = input[idx+1] * (right[idx] - left[idx] - 1);
        maxArea = max(maxArea, area);
    }

    return maxArea;

}

int32_t main()
{
	readFile();
    int n; cin >> n;

    vector<int> test, left, right;

    for(int i = 0; i < n; ++i)
    {
        
        int temp;
        cin >> temp;
        test.push_back(temp);
    }

    smallestLeftandRight(test, left, right);

    cout << maxAreaHistogram(test, left, right) << endl;
    
    
}
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <list>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <tuple>
#include <deque>
#include <complex>
#include <bitset>
#include <functional>
#include <cassert>
//#include <atcoder/all>

using namespace std;
//using namespace atcoder;

using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;
using ld = long double;
using vld = vector<ld>;
using vb = vector<bool>;

#define rep(i, n) for (ll i = 0; i < (n); i++)
#ifdef LOCAL
#define dbg(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl
#else
#define dbg(x) true
#endif

template <class T> bool chmin(T& a, T b) {
    if(a > b) { a = b; return true; }
    else return false;
}

template <class T> bool chmax(T& a, T b) {
    if(a < b) { a = b; return true; }
    else return false;
}

template <class T> ostream& operator<<(ostream& s, const vector<T>& a) {
    for(auto i : a) s << i << ' ';
    return s;
}

constexpr ll INFL = 1LL << 60;
constexpr ld EPS = 1e-12;
ld PI = acos(-1.0);

void solve() {
    ll n;
    cin >> n;
    stack<pll> st;
    ll ans = 0;
    vll A(n+1);
    rep(i, n) cin >> A[i];
    rep(i, n+1) {
        ll a = A[i];
        if(st.empty()) st.emplace(a, i);
        else if(a > st.top().first) st.emplace(a, i);
        else if(a < st.top().first) {
            ll l = i;
            while(!st.empty() && a < st.top().first) {
                pll p = st.top();
                st.pop();
                chmax(ans, p.first * (i - p.second));
                l = p.second;
            }
            st.emplace(a, l);
        }
    }
    cout << ans << endl;
    return;
}

int main() {
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
}