//#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;
    
    vector< pair<int,int> > v;
    for(int i = 0; i < n; ++i) {
        cin >> a[i];
        v.push_back({-a[i], i});
    }
    long long ans = 0;
    sort(v.begin(), v.end());
    int ll = v[0].second, rr = v[0].second;
    for(int i = 1; i < n; ++i) {
        ans = max(ans, (-v[i].first) * 1ll * (max(abs(ll-v[i].second), abs(rr-v[i].second))));
        
        ll = min(ll, v[i].second);
        rr = max(rr, v[i].second);
    }
    cout << ans << "\n";
    return 0;
}
