#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int N;
const int M = 10000;
const int m = 100;
int A[M], B[m];

void init() {
    int min_v = 1000000;
    for (int i = 0; i < m; i++) {
        min_v = 1000000;
        for (int j = i * m; j < (i + 1) * m; j++) {
            min_v = min(min_v, A[j]);
        }
        B[i] = min_v;
    }
}

int getLeft(int i) {
    int ret = 0;
    int b = i / m; // iが所属するバケットの要素番号
    // iが所属するバケット内を走査
    for (int j = i - 1; j >= b * m; j--) {
        if (A[j] >= A[i]) ret++;
        else return ret;
    }
    if (b == 0) return ret;
    b--;
    while (b >= 0) {
        if (B[b] >= A[i]) b--;
        else break;
    }
    if (b == -1) return ret + m * (i / m);
    for (int j = (b + 1) * m - 1; j >= b * m; j--) {
        if (A[j] >= A[i]) ret++;
        else break;
    }
    return ret + m * (i / m - b - 1);
}

int getRight(int i) {
    int b = i / m;
    int ret = 0;
    for (int j = i + 1; j < (b + 1) * m; j++) {
        if (A[j] >= A[i]) ret++;
        else return ret;
    }
    if (b == m - 1) return ret;
    b++;
    while (b < m) {
        if (B[b] >= A[i]) b++;
        else break;
    }
    if (b == m) return ret + m * (m - i / m - 1);
    for (int j = b * m; j < (b + 1) * m; j++) {
        if (A[j] >= A[i]) ret++;
        else break;
    }
    return ret + m * (b - i / m - 1);
}

int main() {
    cin >> N;
    int best = 0;
    fill(A, A + M, 0);
    fill(B, B + m, 0);
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }
    init();
    for (int i = 0; i < N; i++) {
        int l = 1 + getLeft(i) + getRight(i);
        best = max(best, A[i] * l);
    }
    cout << best << "\n";
    return 0;
}
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define fast                     \
    ios::sync_with_stdio(false); \
    cin.tie(0);

void solve(int, int, vector<ll> &, vector<int> &, ll, int);

int main()
{
    int ans = 0;

    int n;
    cin >> n;
    vector<int> heights(n);
    for (auto &i : heights)
        cin >> i;

    stack<int> s;
    heights.push_back(0);

    for (int i = 0; i < heights.size(); i++)
    {
        while (!s.empty() && heights[s.top()] >= heights[i])
        {
            int cur = s.top();
            s.pop();

            ans = max(ans, heights[cur] * (s.empty() ? i : (i - s.top() - 1)));
        }
        s.push(i);
    }

    cout << ans;
}
