//#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 <cassert>
#include <queue>

using namespace std;

const int maxn = 100010;

int a[maxn];

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