#include<bits/stdc++.h>
using namespace std;

int main() {
    int n;
    cin>>n;
    int arr[n];
    for(int i = 0; i < n; i++){
        cin>>arr[i];
    }

    stack<int> st;
    int maxArea = 0;

    st.push(0);

    for(int i = 1; i < n; i++){
        if( arr[i] >= arr[st.top()] || st.empty()){
            st.push(i);
        }else{
            while(arr[st.top()] > arr[i]){
                int minHght = arr[st.top()];
                st.pop();
                if(st.size() != 0){
                    int top = st.top();
                    int currArea = (i - top - 1)*minHght;
                    if(currArea > maxArea){
                        maxArea = currArea;
                    }
                }else{
                    int currArea = i*minHght;
                    if(currArea > maxArea){
                        maxArea = currArea;
                    }
                    break;
                }
            }
            st.push(i);
        }
    }

    while(st.size() != 0){
        int minHght = arr[st.top()];
        st.pop();
        if(st.size() != 0){
            int top = st.top();
            int currArea = (n - top - 1)*minHght;
            if(currArea > maxArea){
                maxArea = currArea;
            }
        }else{
            int currArea = n*minHght;
            if(currArea > maxArea){
                maxArea = currArea;
            }
            break;
        }
    }
    cout<<maxArea;
	return 0;
}