#include<iostream>
#include<stack>
using namespace std;
void largestAreaUnderHistogram(long long int arr[], int n) {
    stack<long long int>s;
    long long int area = 0, ans[1000000002], st;
    int i;
    for (i = 0; i < n; i++) {
        int curElement = arr[i];
        if (s.empty() || arr[s.top()] <= curElement) {
            s.push(i);
        }
        else {
            while (!s.empty() && curElement < arr[s.top()]) {
                st=s.top();
                s.pop();
                //comping areas
                if (s.empty()) {
                    area = arr[st] * i;
                     ans[st] = area;
                }
                else {
                    area = arr[st] * (i - s.top()-1);
                    ans[st] = area;
                }
            }
            s.push(i);
        }
    }

    while (s.empty() == false) {
        st=s.top();
        s.pop();
        //comping areas
        if (s.empty()) {
            area = arr[st] * i;
            ans[st] = area;
        }
        else {
            area = arr[st] * (i - s.top()-1);
            ans[st] = area;
        }
        
    }
   long long int Max = 0;
    for (int i = 0; i < n; i++) {
        cout << ans[i] << " ";
        Max = max(Max, ans[i]);
    }
    cout<<endl;
    cout << "maxArea" << Max;
}

int main() {
    long long int arr[1000000002];
    int n;
    cin>>n;
    int i=0;
    while(i<n){
        cin>>arr[i];
        i++;
    }
    largestAreaUnderHistogram(arr, n);
    return 0;
}