//#include "testlib.h"

#include <iostream>
#include <math.h>
#include <map>
#include <vector>
#include <stdlib.h>
#include <memory.h>
#include <time.h>
#include <string.h>
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <set>
#include <stack>
#include <cassert>
#include <queue>

using namespace std;

int a[100010];

int main() {
    ios::sync_with_stdio(0);
    int n; cin >> n;
    for(int i = 0; i < n; ++i)
        cin >> a[i];
    int ans = 0;
    int l = 0, r = n-1;
    while (l < r) {
        ans = max(min(a[l], a[r]) * (r-l), ans);
        if (a[l] <= a[r])
            while (l < r && a[l] <= a[r]) {
                l++;
                ans = max(min(a[l], a[r]) * (r-l), ans);
            }
        else
            while (l < r && a[l] > a[r]) {
                r--;
                ans = max(min(a[l], a[r]) * (r-l), ans);
            }
    }
    cout << ans << "\n";
    return 0;
}
