#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using tiii = tuple<int, int, int>;
using str = string;
using ld = long double;

#define FOR(i,a,b) for(int i = (a);i < (b);i ++)
#define ROF(i,a,b) for(int i = (a);i >= (b);i --)
#define trav(a, b) for(auto& a : b)

#define sz(a) int((a).size())
#define all(a) (a).begin(), (a).end()
#define pb push_back
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound

#define mk make_pair
#define mt make_tuple
#define f first
#define s second

#define LOCAL
#ifdef LOCAL
	#define nme(x) #x << " : " << x << ' '
#else
	#define cerr if(false)cerr
	#define nme(x) #x << " : " << x << ' '
#endif

template<class T> void maxself(T& x, const T& y){x = (y > x ? y : x);}
template<class T> void minself(T& x, const T& y){x = (y < x ? y : x);}

const ld PI = 3.141592653589793238462643;
const ll mod = 1000000007;
struct mi{
	ll val;explicit operator int() const {return val;}
	mi():val(0){}
	mi(ll v):val(v % mod){}
};
mi operator+(const mi& a, const mi& b){return (a.val + b.val) % mod;}
mi operator*(const mi& a, const mi& b){return (a.val * b.val) % mod;}
mi operator-(const mi& a, const mi& b){return (a.val - b.val + mod) % mod;}

const int N = 10000;
int n, a[N], lef[N], rigt[N];

void solve(){
	cin >> n;
	FOR(i,0,n){
		cin >> a[i];
	}

	vector<pii> st;
	FOR(i,0,n){
		while(sz(st) && st.back().f >= a[i]){
			st.pop_back();
		}
		if(sz(st)) lef[i] = st.back().s;
		else lef[i] = -1;
		st.eb(a[i], i);
	}
	st.clear();
	ROF(i,n - 1,0){
		while(sz(st) && st.back().f >= a[i]) st.pop_back();
		if(sz(st)) rigt[i] = st.back().s;
		else rigt[i] = n;
		st.eb(a[i], i);
	}
	int ans = 0;
	FOR(i,0,n){
		maxself(ans, a[i] * (rigt[i] - lef[i] - 1));
	}
	cout << ans << '\n';
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);

	int T = 1;
	// cin >> T;
	while(T --) solve();

	return 0;
}
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pi;
typedef vector<ll> vi;
typedef vector<pi> vpi;
typedef long double ld;
const int inf = 1e9 + 7;
const int mod = 998244353;
const int maxn = 1e6 + 3;
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define rep(i, a, b) for(int i = a; i < b; i++)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define lb lower_bound
#define ub upper_bound
#define fact(n) rep(i, 1, n+1)ft.pb((ft[i-1]*i)%mod);
#define mod_in(a) exp(a, mod-2)
#define ncr(n, r) ((ft[n]*mod_in((ft[r]*ft[(n)-(r)])%mod))%mod)
#define deb(x) cout << #x << " " << x << endl;
#define flash ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl '\n'

/*#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<typename T>
using ordered_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
template<typename T>
using ordered_multiset = tree<T,null_type,less_equal<T>,rb_tree_tag,tree_order_statistics_node_update>;*/

//cout << fixed << setprecision(0) << ans <<endl;

ll prime[4000005];
ll exp(ll a,ll b);
void sieve(ll n);
ll gcd(ll a ,ll b);
ll sod(ll x);
ll countdigit(ll n);
ll mySqrt(ll x);
vector<ll>ft;
int ans = 0;

int findMin(int arr[], int n)
{
    int sum = 0;
    for (int i = 0; i < n; i++)
        sum += arr[i];
    bool dp[n+1][sum+1];
    for (int i = 0; i <= n; i++)
        dp[i][0] = true;
    for (int i = 1; i <= sum; i++)
        dp[0][i] = false;
    for (int i=1; i<=n; i++)
    {
        for (int j=1; j<=sum; j++)
        {
            
            dp[i][j] = dp[i-1][j];
 
            // If i'th element is included
            if (arr[i-1] <= j)
                dp[i][j] |= dp[i-1][j-arr[i-1]];
        }
    }
    int diff = INT_MAX;
    for (int j=sum/2; j>=0; j--)
    {
        // Find the
        if (dp[n][j] == true)
        {
            //cout << 2*j << " " << sum-j << endl;
            ans = max(j,sum-j);
            diff = sum-2*j;
            break;
        }
    }
    return diff;
}
 


int main()
{   
    flash;
    ll t=1;
   // sieve(4000003);
    //ft.pb(1);
    //fact(10000001);
    //cin >> t;
    while(t--) {
        int n;
        cin >> n;
        int v[n];
        rep(i,0,n)cin >> v[i];
        ll i = 0, j = n-1;
        int res = findMin(v,n);
        cout << ans << endl;
        
    }
}

//
//
//
//
//
// IMPORTANT FUNCTIONS
ll exp(ll a, ll b) {
	int res=1;
	while(b) {
		if(b&1)
			res=(res*a)%mod;
		a=(a*a)%mod;
		b>>=1;
	}
	return res%mod;
}
ll gcd(ll a,ll b){
    if(a==0)return b;
    return gcd(b%a,a);
}
void sieve(ll n) {
    for(ll i=0;i<=n;i++) {
        prime[i]=1;
    }
    prime[0]=0;prime[1]=0;
    for(ll i=2;i<=n;i++) {
        if(prime[i]==1) {
            for(ll j=2;i*j<=n;j++) {
                prime[i*j]=0;
            }
        }
    }
}
ll countdigit(ll  n)
{
    return floor(log10(n) + 1);
}
ll sod(ll x){
    ll s = 0;
    while (x != 0) {
      s = s + x % 10;
      x = x / 10;
   }
   return s;
}
ll mySqrt(ll x)
{
    if (x == 0 || x == 1)
    {
        return x;
    }
    ll start = 1, end = x / 2;
    // standard binary search template
    while (start + 1 < end)
    {
        ll mid = start + (end - start) / 2;
        // why not mid * mid <= x? because it may cause overflow when mid is very large
        if (mid <= x / mid)
        {
            start = mid;
        }
        else
        {
            end = mid - 1;
        }
    }
    return end <= x / end ? end : start;
}