//#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});
    }
    sort(v.begin(), v.end());
    long long ans = 0;
    for(int i = 0; i < n; ++i) {
        for(int j = 0; j < n && j < 500; ++j)
            ans = max(ans, abs(i - v[j].second) * 1ll * min(a[i], a[v[j].second]));
        for(int j = max(0, n-500); j < n; ++j)
            ans = max(ans, abs(i - v[j].second) * 1ll * min(a[i], a[v[j].second]));
    }
    
    for(int l = 0; l < n && l < 500; ++l)
        for(int r = max(l+1, n-500); r < n; ++r)
            ans = max(ans, (r-l)*1ll*min(a[l], a[r]));
    
    for(int i = 0; i < n; ++i)
        for(int j = max(0, i-500); j <= min(n-1, i+500); ++j)
            ans = max(ans, abs(i-j) * 1ll * min(a[i], a[j]));
    
    for(int i = 0; i < n; ++i) {
        
        for(int j = 0; j < 500 && j < n; ++j)
            ans = max(ans, abs(i-j) * 1ll * min(a[i], a[j]));
        for(int j = max(0, n-500); j < n; ++j)
            ans = max(ans, abs(i-j) * 1ll * min(a[i], a[j]));

    }
    
    cout << ans << "\n";
    return 0;
}
