#include <iostream>
#include <string>
#include <vector>
#include <math.h>
using namespace std;

void main()
{
    long long c=0;
    long long n,d;
    cin>>n;
    cin>>d;
    long long * mas=new long long[n+1];
    for (long long h=0;h<n;h++)
    {
        cin>>mas[h];
    }
    mas[n+1]=mas[n]+1;
    long long i=0;
    while(i<n-1)
    {
        if(mas[i+1]<=mas[i]){mas[i+1]=mas[i+1]+d;c++;i=i-1;}
        i++;
    }
    cout<<c;

}


#include <iostream>
#include <string>
#include <vector>
#include <math.h>
using namespace std;

void main()
{
    int c=0;
    int n,d;
    cin>>n;
    cin>>d;
    int * mas=new int[n];
    for (int h=0;h<n;h++)
    {
        cin>>mas[h];
    }
    for(int i=0;i<n;i++)
    {
        if(i>=1)
        {
            if(mas[i]<=mas[i-1])
            {
                int g=(mas[i-1]-mas[i])/d+1;
                c=c+((mas[i-1]-mas[i])/d+1);
                mas[i]=mas[i]+g*d;
            }
        }
    }

    //for (int h=0;h<n;h++)
    //{
    //  cout<<" "<<mas[h]<<" ";
    //}

    cout<<c;

}


#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <cmath>

#define forn(i,n) for (int i=0;i<n;i++)
#define ford(i,n) for (int i=n-1;i>=0;i--)
#define mp make_pair
#define pb push_back
#define x first
#define y second
#define pi 3.1415926535897932

using namespace std;

int main(){
    //freopen ("input.txt","rt",stdin);
    //freopen ("output.txt","wt",stdout);
    int n,d,schet;
    int a[2000];
    cin >> n >> d;
    forn(i,n)
        scanf ("%d ", &a[i]);
    forn(i,n-1)
        while (a[i+1]<=a[i]){
            a[i+1]+=d;
            schet++;
        }
    cout << schet;
    return 0;
}


#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <cmath>

#define forn(i,n) for (int i=0;i<n;i++)
#define ford(i,n) for (int i=n-1;i>=0;i--)
#define mp make_pair
#define pb push_back
#define x first
#define y second
#define pi 3.1415926535897932

using namespace std;

int main(){
    //freopen ("input.txt","rt",stdin);
    //freopen ("output.txt","wt",stdout);
    int n,d,schet=0;
    int a[2000];
    cin >> n >> d;
    forn(i,n)
        scanf ("%d ", &a[i]);
    forn(i,n-1)
        while (a[i+1]<=a[i]){
            a[i+1]+=d;
            schet++;
        }
    cout << schet;
    return 0;
}


#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <cmath>

#define forn(i,n) for (int i=0;i<n;i++)
#define ford(i,n) for (int i=n-1;i>=0;i--)
#define mp make_pair
#define pb push_back
#define x first
#define y second
#define pi 3.1415926535897932

using namespace std;

int aaa(int a, int b){
    if (a % b==0) return a/b;
    else return a/b+1;
}

int main(){
    //freopen ("input.txt","rt",stdin);
    //freopen ("output.txt","wt",stdout);
    int n,d,schet=0,help,z;
    int a[2000];
    cin >> n >> d;
    forn(i,n)
        scanf ("%d ", &a[i]);
    forn(i,n-1){
        int help=a[i]-a[i+1]+1;
        if (help>0){
            z=aaa(help,d);
            a[i+1]+=d*z;
            schet+=z;
        }
    }
    cout << schet;
    return 0;
}


#include <iostream>
#include < fstream>
#include< cstdlib>
#include <string>
#include <vector>
#include <cmath>
using namespace std;

int main()
{

    int n, d;
    string x;
    int count=0;
    vector <int> v;

    cin >>n;
    cin>>d;

    for ( int i = 0; i < n-1; i++)
    {
        getline(cin, x, ' ');

        v.push_back(atoi(x.c_str()));
    }

    cin>> x;
    v.push_back(atoi(x.c_str()));

    for (int j=1; j< n;j++)
    {
        int x;
        x= v[j]-v[j-1];

        if (x==0)
        {
            v[j]+= d;
            count++;
        }

        if (x<0)
        {
            int f;
            x*= -1;
            if (x%d != 0)
                f = 1;
            else
                f=0;

            count += (x/ d) + f;
            v[j] += (((x/ 2) + (f)) * 2) ;

        }

    }

    cout << count;
    return 0;

}


#include <iostream>
#include < fstream>
#include< cstdlib>
#include <string>
#include <vector>
using namespace std;

int main()
{

    string n, d,x;
    int count=0, a,b;
    vector <int> v;

    getline(cin, n, ' ');
    cin>>d;

    a= atoi(n.c_str());
    b= atoi(d.c_str());
    for ( int i = 0; i < a-1; i++)
    {
        getline(cin, x, ' ');

        v.push_back(atoi(x.c_str()));
    }

    cin>> x;
    v.push_back(atoi(x.c_str()));

    for (int j=1; j< a;j++)
    {
        while( v[j] <= v[j-1])
        {
            v[j] += b;
            count++;
        }
    }

    cout << count;

    return 0;

}


#include <iostream>
#include < fstream>
#include< cstdlib>
#include <string>
#include <vector>
#include <cmath>
using namespace std;

int main()
{

    int n, d;
    string x;
    int count=0;
    vector <int> v;

    cin >>n;
    cin>>d;

    for ( int i = 0; i < n-1; i++)
    {
        getline(cin, x, ' ');

        v.push_back(atoi(x.c_str()));
    }

    cin>> x;
    v.push_back(atoi(x.c_str()));

    for (int j=1; j< n;j++)
    {
        int x;
        x= v[j]-v[j-1];

        if (x==0)
        {
            v[j]+= 2;
            count++;
        }

        if (x<0)
        {
            x*= -1;
            count += (x/ 2) + (x%2);
            v[j] += (((x/ 2) + (x%2)) * 2) ;

        }

    }

    cout << count;
    return 0;

}


#include <iostream>
#include < fstream>
#include< cstdlib>
#include <string>
#include <vector>
using namespace std;

int main()
{

    string n, d,x;
    int count=0, a,b;
    vector <int> v;

    getline(cin, n, ' ');
    cin>>d;

    a= atoi(n.c_str());
    b= atoi(d.c_str());
    for ( int i = 0; i < a; i++)
    {
        getline(cin, x, ' ');

        v.push_back(atoi(x.c_str()));
    }

    for (int j=1; j< a;j++)
    {
        while( v[j] <= v[j-1])
        {
            v[j] += b;
            count++;
        }
    }

    cout << count;

    return 0;

}


#include <iostream>
#include < fstream>
#include< cstdlib>
#include <string>
#include <vector>
#include <cmath>
using namespace std;

int main()
{

    int n, d;
    string x;
    int count=0;
    vector <int> v;

    cin >>n;
    cin>>d;

    for ( int i = 0; i < n-1; i++)
    {
        getline(cin, x, ' ');

        v.push_back(atoi(x.c_str()));
    }

    cin>> x;
    v.push_back(atoi(x.c_str()));

    for (int j=1; j< n;j++)
    {
        int x;
        x= v[j]-v[j-1];

        if (x==0)
        {
            v[j]+= d;
            count++;
        }

        if (x<0)
        {
            int f;
            x*= -1;

            count += (x/ d) + 1;
            v[j] += (((x/ d) + (1)) * d) ;

        }

    }

    cout << count;
    return 0;

}


#include <iostream>
#include < fstream>
#include< cstdlib>
#include <string>
#include <vector>
#include <cmath>
using namespace std;

int main()
{

    int n, d;
    string x;
    int count=0;
    vector <int> v;

    cin >>n;
    cin>>d;

    for ( int i = 0; i < n-1; i++)
    {
        getline(cin, x, ' ');

        v.push_back(atoi(x.c_str()));
    }

    cin>> x;
    v.push_back(atoi(x.c_str()));

    for (int j=1; j< n;j++)
    {
        int x;
        x= v[j]-v[j-1];

        if (x==0)
        {
            v[j]+= d;
            count++;
        }

        if (x<0)
        {
            int f;
            x*= -1;
            if (x%d != 0)
                f = 1;
            else
                f=0;

            count += (x/ d) + f;
            v[j] += (((x/ d) + (f)) * d) ;

        }

    }

    cout << count;
    return 0;

}


#include<iostream>
using namespace std;

typedef long long LL;

LL d[2010];
LL ans;

int main()
{
    LL n,D;

    scanf("%I64d%I64d%I64d",&n,&D,d);
    ans=0;
    for(int i=1;i<n;++i){
        scanf("%I64d",d+i);
        //while(d[i] < d[i-1]) d[i]+=D,ans++;

        if(d[i] <= d[i-1]){
            LL ct =  (d[i-1]-d[i])/D + 1;
            d[i] = d[i-1]+ct *D;
            ans+=ct;
        }
    }
    printf("%I64d\n",ans);

    return 0;
}


#include<iostream>
using namespace std;

typedef long long LL;

LL d[2010];
LL ans;

int main()
{
    LL n,D;

    scanf("%I64d%I64d%I64d",&n,&D,d);
    ans=0;
    for(int i=1;i<n;++i){
        scanf("%I64d",d+i);
        //while(d[i] <= d[i-1]) d[i]+=D,ans++;

        if(d[i] <= d[i-1]){
            LL ct =  (d[i-1]-d[i])/D + 1;
            d[i] += ct *D;
            ans+=ct;
        }
    }
    printf("%I64d\n",ans);

    return 0;
}


#include<iostream>
using namespace std;

typedef long long LL;

LL d[2010];
LL ans;

int main()
{
    LL n,D;

    scanf("%I64d%I64d%I64d",&n,&D,d);
    ans=0;
    for(int i=1;i<n;++i){
        scanf("%I64d",d+i);
        while(d[i] <= d[i-1]) d[i]+=D,ans++;

        /*
        if(d[i] <= d[i-1]){
            LL ct =  (d[i-1]-d[i])/D + 1;
            d[i] = d[i-1]+ct *D;
            ans+=ct;
        }*/
    }
    printf("%I64d\n",ans);

    return 0;
}


#include<iostream>
using namespace std;

int d[2010];
int ans;

int main()
{
    int n,D;
    int i,j,k;
    scanf("%d%d%d",&n,&D,d);
    ans=0;
    for(i=1;i<n;++i){
        scanf("%d",d+i);
        //while(d[i] < d[i-1]) d[i]+=D,ans++;

        if(d[i] <= d[i-1]){
            int ct =  (d[i-1]-d[i])/D + 1;
            d[i] = d[i-1]+ct *D;
            ans+=ct;
        }
    }
    printf("%d\n",ans);

    return 0;
}


#include<iostream>
using namespace std;

typedef long long LL;

LL d[2010];
LL ans;

int main()
{
    int n,D;
    int i,j,k;
    scanf("%d%d%I64d",&n,&D,d);
    ans=0;
    for(i=1;i<n;++i){
        scanf("%I64d",d+i);
        //while(d[i] < d[i-1]) d[i]+=D,ans++;

        if(d[i] <= d[i-1]){
            LL ct =  (d[i-1]-d[i])/D + 1;
            d[i] = d[i-1]+ct *D;
            ans+=ct;
        }
    }
    printf("%I64d\n",ans);

    return 0;
}


#include<iostream>
using namespace std;

int d[2010];
int ans;

int main()
{
    int n,D;
    int i,j,k;
    scanf("%d%d%d",&n,&D,d);
    ans=0;
    for(i=1;i<n;++i){
        scanf("d",d+i);
        //while(d[i] < d[i-1]) d[i]+=D,ans++;

        if(d[i] < d[i-1]){
            int ct =  (d[i-1]-d[i])/D + 1;
            d[i] = ct *D;
            ans+=ct;
        }
    }
    printf("%d\n",ans);

    return 0;
}


#include<iostream>
using namespace std;

int d[2010];
int ans;

int main()
{
    int n,D;
    int i,j,k;
    scanf("%d%d%d",&n,&D,d);
    ans=0;
    for(i=1;i<n;++i){
        scanf("d",d+i);
        while(d[i] < d[i-1]) d[i]+=D,ans++;

        if(d[i] < d[i-1]){
            int ct =  (d[i-1]-d[i])/D + 1;
            d[i] = ct *D;
            ans+=ct;
        }
    }
    printf("%d\n",ans);

    return 0;
}


#include<stdio.h>
#include <iostream>
#include<conio.h>

int main()
{
int n,q,s;
int a[1000000];
scanf("%d%d",&n,&q);
for(int i=1;i<n+1;i++){
scanf("%d",&s);
a[i]=s;
}
int raz,ito;
int shag=0;
for(int i=2;i<n+1;i++){
    if (a[i]<=a[i-1]) {
      raz=abs(a[i]-a[i-1]);
      ito=(raz/q)+1;
      a[i]=a[i]+ito*q+1;
      shag=shag+ito;
    }
}

printf("%d",shag);
}


#include<stdio.h>
#include <iostream>
#include<conio.h>

int main()
{
int n,q,s;
int a[1000000];
scanf("%d%d",&n,&q);
for(int i=1;i<n+1;i++){
scanf("%d",&s);
a[i]=s;
}
int raz,ito;
int shag=0;
for(int i=2;i<n+1;i++){
    if (a[i]<=a[i-1]) {
      raz=abs(a[i]-a[i-1]);
      ito=(raz/q)+1;
      a[i]=a[i]+ito*q;
      shag=shag+ito;
    }
}

printf("%d",shag);
}


#include<stdio.h>
#include <iostream>
#include<conio.h>

int main()
{
int n,q,s;
int a[1000000];
scanf("%d%d",&n,&q);
for(int i=1;i<n+1;i++){
scanf("%d",&s);
a[i]=s;
}
int shag=0;
for(int i=2;i<n+1;i++){
    if (a[i]<=a[i-1]) {
        while (a[i-1]>=a[i]){
            a[i]=a[i]+q;
            shag++;
        }
    }
}
printf("%d",shag);
}


#include<stdio.h>
#include <iostream>
#include<conio.h>

int main()
{
int n,q,s;
int a[100];
scanf("%d%d",&n,&q);
for(int i=1;i<n+1;i++){
scanf("%d",&s);
a[i]=s;
}
int shag=0;
for(int i=2;i<n+1;i++){
    if (a[i]<=a[i-1]) {
        while (a[i-1]>=a[i]){
            a[i]=a[i]+q;
            shag++;
        }
    }
}
printf("%d",shag);
}


// 11A.cpp: определяет точку входа для консольного приложения.
//

#include<stdio.h>
#include <iostream>
#include<conio.h>

int main()
{
int n,q,s;
int a[1000000];
scanf("%d%d",&n,&q);
for(int i=1;i<n+1;i++){
scanf("%d",&s);
a[i]=s;
}
int raz,ito;
int shag=0;
for(int i=2;i<n+1;i++){
    if (a[i]<=a[i-1]) {
      raz=abs(a[i]-a[i-1]);
      ito=(raz/q)+1;
      a[i]=a[i]+raz+1;
      shag=shag+ito;
    }
}

printf("%d",shag);
}


#include<iostream>
using namespace std;
int main()
{
    int n,s,i,j;
    int num[2005];
    long d;
    while(cin>>n>>d)
    {
        for(i=0;i<n;i++)
            cin>>num[i];
        int cnt =0;
        for(i=1,j=0;i<n;i++,j++)
        {
            if(num[i] < num[j])
            {
                s=num[j]-num[i];
                if(s%d == 0)
                {
                    cnt+=s/d;
                    num[i]+=s;
                }
                else
                {
                    num[i]+=(s/d+1)*d;
                    cnt+=s/d+1;
                }
            }
            if(num[i] == num[j])
            {
                num[i]+=d;
                cnt++;
            }
        }
        cout<<cnt<<endl;
    }
    return 0;
}


#include<iostream>
using namespace std;
int main()
{
    int n,i;
    int num[2005];
    long d;
    while(cin>>n>>d)
    {
        for(i=0;i<n;i++)
            cin>>num[i];
        int cnt =0,j = 0;
            for(i=1;i<n;i++)
            {
                while(num[i] <= num[j])
                {
                    num[i] += d;
                    cnt++;
                }
                j++;
            }
            cout<<cnt<<endl;
    }
    return 0;
}


#include<iostream>
using namespace std;

int main()
{
    int a,b,c,d;
    int temp;
    int n,sum;
    int pre=0;
    while(cin>>n>>temp)
    {
        sum = 0;
        while(n --)
        {
            cin>>a;
            if(a>pre)
            {
                pre = a;
                continue;
            }
            else
            {

                int t=(pre-a)/temp;
                while(a+t*temp<=pre)
                {
                    t++;
                }
                sum +=t;
                pre = a+t*temp;
            }
        }
        cout << sum << endl;
    }
return 0;
}


#pragma warning( disable : 4996)
#pragma comment(linker, "/STACK:666000000")

#define bublic public

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <limits.h>
#include <list>
#include <map>
#include <set>
#include <string>
#include <time.h>
#include <vector>
#include <stack>
#include <queue>

#define nextLine() {for(int c=getchar(); c!='\n' && c!=EOF; c=getchar());}
#define sqr(a) ((a)*(a))
#define has(mask,i) (((mask) & (1<<(i))) == 0 ? false : true)
#define eprintf(...) fprintf(stderr, __VA_ARGS__)

#define TASK "file"

using namespace std;

#define pii pair<int,int>
#define mp(x, y) make_pair(x, y)
#define pb(_o_) push_back(_o_)

typedef long long LL;
typedef unsigned long long ULL;
typedef long double ldb;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<int> vb;
typedef vector<vi> vvb;
typedef list<int> li;
typedef multiset<int>::iterator siit;

const int inf = (1 << 30) - 1;
const ldb eps = 1e-9;
const ldb pi = fabs(atan2(0.0, -1.0));

#ifndef ONLINE_JUDGE
#define parr(a,n,m) for(int i=0;i<n;i++){for(int j=0;j<m;j++)cout<<a[i][j]<<" ";puts("");}puts("");
#else
#define parr(a,n,m) for(int i=0;i<2;i++)i++;
#endif

void ML()
{
    int *ass;
    for (;;)
    {
        ass = new int[2500000];
        for (int i = 0; i < 2500000; i++)
            ass[i] = rand();
    }
}

int n, d;
int a[3000];

void LoAd()
{
    cin >> n >> d;
    for (int i = 0; i < n; i++)
        scanf("%d", &a[i]);
}

void SoLvE()
{
    LL cnt = 0;
    for (int i = 1; i < n; i++)
    {
        if (a[i] <= a[i-1])
        {
            int dif = a[i-1] - a[i] + 1;
            while (dif > 0)
            {
                cnt++;
                dif -= d;
            }
            /*
            cnt += (a[i-1] + 1 - a[i]) / d;
            if ((a[i-1] + 1 - a[i]) % d != 0)
                cnt++;
            */
            a[i] = a[i-1] + 1;
        }
    }
    cout << cnt;
}

int main()
{
    srand( (int) time(NULL));
#ifndef ONLINE_JUDGE
    freopen(TASK".in","r",stdin);   freopen(TASK".out","w",stdout);
#endif
    LoAd();
    SoLvE();
    return 0;
}


#pragma warning( disable : 4996)
#pragma comment(linker, "/STACK:666000000")

#define bublic public

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <limits.h>
#include <list>
#include <map>
#include <set>
#include <string>
#include <time.h>
#include <vector>
#include <stack>
#include <queue>

#define nextLine() {for(int c=getchar(); c!='\n' && c!=EOF; c=getchar());}
#define sqr(a) ((a)*(a))
#define has(mask,i) (((mask) & (1<<(i))) == 0 ? false : true)
#define eprintf(...) fprintf(stderr, __VA_ARGS__)

#define TASK "file"

using namespace std;

#define pii pair<int,int>
#define mp(x, y) make_pair(x, y)
#define pb(_o_) push_back(_o_)

typedef long long LL;
typedef unsigned long long ULL;
typedef long double ldb;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<int> vb;
typedef vector<vi> vvb;
typedef list<int> li;
typedef multiset<int>::iterator siit;

const int inf = (1 << 30) - 1;
const ldb eps = 1e-9;
const ldb pi = fabs(atan2(0.0, -1.0));

#ifndef ONLINE_JUDGE
#define parr(a,n,m) for(int i=0;i<n;i++){for(int j=0;j<m;j++)cout<<a[i][j]<<" ";puts("");}puts("");
#else
#define parr(a,n,m) for(int i=0;i<2;i++)i++;
#endif

void ML()
{
    int *ass;
    for (;;)
    {
        ass = new int[2500000];
        for (int i = 0; i < 2500000; i++)
            ass[i] = rand();
    }
}

int n, d;
int a[3000];

void LoAd()
{
    cin >> n >> d;
    for (int i = 0; i < n; i++)
        scanf("%d", &a[i]);
}

void SoLvE()
{
    LL cnt = 0;
    for (int i = 1; i < n; i++)
    {
        if (a[i] <= a[i-1])
        {
            cnt += (a[i-1] + 1 - a[i]) / d;
            if ((a[i-1] + 1 - a[i]) % d != 0)
                cnt++;
            a[i] = a[i-1] + 1;
        }
    }
    cout << cnt;
}

int main()
{
    srand( (int) time(NULL));
#ifndef ONLINE_JUDGE
    freopen(TASK".in","r",stdin);   freopen(TASK".out","w",stdout);
#endif
    LoAd();
    SoLvE();
    return 0;
}


#pragma warning( disable : 4996)
#pragma comment(linker, "/STACK:666000000")

#define bublic public

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <limits.h>
#include <list>
#include <map>
#include <set>
#include <string>
#include <time.h>
#include <vector>
#include <stack>
#include <queue>

#define nextLine() {for(int c=getchar(); c!='\n' && c!=EOF; c=getchar());}
#define sqr(a) ((a)*(a))
#define has(mask,i) (((mask) & (1<<(i))) == 0 ? false : true)
#define eprintf(...) fprintf(stderr, __VA_ARGS__)

#define TASK "file"

using namespace std;

#define pii pair<int,int>
#define mp(x, y) make_pair(x, y)
#define pb(_o_) push_back(_o_)

typedef long long LL;
typedef unsigned long long ULL;
typedef long double ldb;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<int> vb;
typedef vector<vi> vvb;
typedef list<int> li;
typedef multiset<int>::iterator siit;

const int inf = (1 << 30) - 1;
const ldb eps = 1e-9;
const ldb pi = fabs(atan2(0.0, -1.0));

#ifndef ONLINE_JUDGE
#define parr(a,n,m) for(int i=0;i<n;i++){for(int j=0;j<m;j++)cout<<a[i][j]<<" ";puts("");}puts("");
#else
#define parr(a,n,m) for(int i=0;i<2;i++)i++;
#endif

void ML()
{
    int *ass;
    for (;;)
    {
        ass = new int[2500000];
        for (int i = 0; i < 2500000; i++)
            ass[i] = rand();
    }
}

int n, d;
int a[3000];

void LoAd()
{
    cin >> n >> d;
    for (int i = 0; i < n; i++)
        scanf("%d", &a[i]);
}

void SoLvE()
{
    LL cnt = 0;
    for (int i = 1; i < n; i++)
    {
        if (a[i] <= a[i-1])
        {
            cnt += (a[i-1] - a[i] + d) / d;
            a[i] = a[i-1] + 1;
        }
    }
    cout << cnt;
}

int main()
{
    srand( (int) time(NULL));
#ifndef ONLINE_JUDGE
    freopen(TASK".in","r",stdin);   freopen(TASK".out","w",stdout);
#endif
    LoAd();
    SoLvE();
    return 0;
}


#pragma warning( disable : 4996)
#pragma comment(linker, "/STACK:666000000")

#define bublic public

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <limits.h>
#include <list>
#include <map>
#include <set>
#include <string>
#include <time.h>
#include <vector>
#include <stack>
#include <queue>

#define nextLine() {for(int c=getchar(); c!='\n' && c!=EOF; c=getchar());}
#define sqr(a) ((a)*(a))
#define has(mask,i) (((mask) & (1<<(i))) == 0 ? false : true)
#define eprintf(...) fprintf(stderr, __VA_ARGS__)

#define TASK "file"

using namespace std;

#define pii pair<int,int>
#define mp(x, y) make_pair(x, y)
#define pb(_o_) push_back(_o_)

typedef long long LL;
typedef unsigned long long ULL;
typedef long double ldb;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<int> vb;
typedef vector<vi> vvb;
typedef list<int> li;
typedef multiset<int>::iterator siit;

const int inf = (1 << 30) - 1;
const ldb eps = 1e-9;
const ldb pi = fabs(atan2(0.0, -1.0));

#ifndef ONLINE_JUDGE
#define parr(a,n,m) for(int i=0;i<n;i++){for(int j=0;j<m;j++)cout<<a[i][j]<<" ";puts("");}puts("");
#else
#define parr(a,n,m) for(int i=0;i<2;i++)i++;
#endif

void ML()
{
    int *ass;
    for (;;)
    {
        ass = new int[2500000];
        for (int i = 0; i < 2500000; i++)
            ass[i] = rand();
    }
}

int n, d;
int a[3000];

void LoAd()
{
    cin >> n >> d;
    for (int i = 0; i < n; i++)
        scanf("%d", &a[i]);
}

void SoLvE()
{
    LL cnt = 0;
    for (int i = 1; i < n; i++)
    {
        if (a[i] <= a[i-1])
        {
            int tmp =  (a[i-1] + 1 - a[i]) / d;
            if ((a[i-1] + 1 - a[i]) % d != 0)
                tmp++;

            a[i] += tmp * d;
            cnt += tmp;
        }
    }
    cout << cnt;
}

int main()
{
    srand( (int) time(NULL));
#ifndef ONLINE_JUDGE
    freopen(TASK".in","r",stdin);   freopen(TASK".out","w",stdout);
#endif
    LoAd();
    SoLvE();
    return 0;
}


#include<iostream>
#include<conio.h>
#include<cstdio>
using namespace std;
_int64 Count;
void main()
{
	int n,prev,temp;
	double *a,d;
	scanf("%d%lf",&n,&d);
	a=(double *)malloc((n+1)*sizeof(double));
	for(int i=1;i<=n;i++)
		scanf("%lf",&a[i]);
	prev=a[1];
	for(int i=2;i<=n;i++)
	{
		if(a[i]<prev)
		{
			temp=ceil((prev-a[i])/d);
			Count+=temp;
			a[i]+=temp*d;
			if(a[i]==prev)
			{
				Count+=1;
				a[i]+=d;
			}
		}
		else if(a[i]==prev)
		{
			Count+=1;
			a[i]+=d;
		}
		prev=a[i];
	}
	cout<<Count<<endl;
	//getch();
}


#include<iostream>
#include<conio.h>
#include<cstdio>
using namespace std;
_int64 Count;
void main()
{
	int n,d,prev,temp;
	float *a;
	scanf("%d%d",&n,&d);
	a=(float *)malloc((n+1)*sizeof(float));
	for(int i=1;i<=n;i++)
		scanf("%f",&a[i]);
	prev=a[1];
	for(int i=2;i<=n;i++)
	{
		if(a[i]<prev)
		{
			temp=ceil((prev-a[i])/2);
			Count+=temp;
			a[i]+=temp*d;
		}
		else if(a[i]==prev)
		{
			Count+=1;
			a[i]+=d;
		}
		prev=a[i];
	}
	cout<<Count<<endl;
	//getch();
}


#include<iostream>
#include<conio.h>
#include<cstdio>
using namespace std;
_int64 Count;
void main()
{
	int n,prev,temp;
	float *a,d;
	scanf("%d%f",&n,&d);
	a=(float *)malloc((n+1)*sizeof(float));
	for(int i=1;i<=n;i++)
		scanf("%f",&a[i]);
	prev=a[1];
	for(int i=2;i<=n;i++)
	{
		if(a[i]<prev)
		{
			temp=ceil((prev-a[i])/d);
			Count+=temp;
			a[i]+=temp*d;
		}
		else if(a[i]==prev)
		{
			Count+=1;
			a[i]+=d;
		}
		prev=a[i];
	}
	cout<<Count<<endl;
	//getch();
}


#include<iostream>
#include<conio.h>
#include<cstdio>
using namespace std;
_int64 Count;
void main()
{
	int n,d,prev,*a;
	scanf("%d%d",&n,&d);
	a=(int *)malloc((n+1)*sizeof(int));
	for(int i=1;i<=n;i++)
		scanf("%d",&a[i]);
	prev=a[1];
	for(int i=2;i<=n;i++)
	{
		if(a[i]<=prev)
			while(a[i]<=prev)
			{
				a[i]+=d;
				++Count;
			}
		prev=a[i];
	}
	cout<<Count<<endl;
	//getch();
}


#include<iostream>
#include<conio.h>
#include<cstdio>
using namespace std;
_int64 Count;
void main()
{
	int n,prev,temp;
	float *a,d;
	scanf("%d%f",&n,&d);
	a=(float *)malloc((n+1)*sizeof(float));
	for(int i=1;i<=n;i++)
		scanf("%f",&a[i]);
	prev=a[1];
	for(int i=2;i<=n;i++)
	{
		if(a[i]<prev)
		{
			temp=ceil((prev-a[i])/d);
			Count+=temp;
			a[i]+=temp*d;
			if(a[i]==prev)
			{
				Count+=1;
				a[i]+=d;
			}
		}
		else if(a[i]==prev)
		{
			Count+=1;
			a[i]+=d;
		}
		prev=a[i];
	}
	cout<<Count<<endl;
	//getch();
}


#include <iostream>
using namespace std;
int main(){
	int n,m,s=0;
	cin>>n>>m;
	int a[n];
	for (int q=1;q<=n;q++){
		cin>>a[q-1];
	}
	for (int i=1;i<=n-1;){
		if (a[i]<=a[i-1]){
			a[i]=a[i]+m;
			s=s+1;
	}
	else {
		i=i+1;
	}
	}
	cout <<s;
	return 0;
}


#include <iostream>
using namespace std;
int main(){
	int n,m,s=0;
	cin>>n>>m;
	int a[n+1];
	for (int q=1;q<=n;q++){
		cin>>a[q-1];
	}
	for (int i=1;i<=n-1;){
		if (a[i]<=a[i-1]){
			a[i]=a[i]+m;
			s=s+1;
	}
	else {
		i=i+1;
	}
	}
	cout <<s;
	return 0;
}


#include <iostream>
using namespace std;
int main(){
	int n,m,a[2000],s=0;
	cin>>n>>m;
	for (int q=1;q<=n;q++){
		cin>>a[q-1];
	}
	for (int i=1;i<=n;i++){
		if (a[i]<=a[i-1]){
			a[i]=a[i]+m;
			i=i-1;
			s=s+1;
	}
	}
	cout <<s;
	return 0;
}


#include <iostream>
using namespace std;
int main(){
	int n,m,s=0,a[2000];
	cin>>n>>m;
	for (int q=1;q<=n;q++){
		cin>>a[q-1];
	}
	for (int i=1;i<=n-1;){
		if (a[i]<=a[i-1]){
			a[i]=a[i]+m;
			s=s+1;
	}
	else {
		i=i+1;
	}
	}
	cout <<s;
	return 0;
}


#include <iostream>
using namespace std;
int main(){
	int n,m,a[2000],s=0;
	cin>>n;
	for (int q=0;q<n;q++){
		cin>>a[q];
	}
	for (int i=1;i<n;i++){
		if (a[i]<a[i-1]){
			a[i]=a[i]+m;
			i=i-1;
			s=s+1;
	}
	}
	cout <<s;
	return 0;
}


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

const int maxn = 1e3 + 10;
ll a[maxn];
ll sum[maxn];
int N;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cin >> N;
  for(int i = 1; i <= N; ++i){
    cin >> a[i];
    sum[i] = sum[i - 1] + a[i];
  }
  if(N == 1){
    cout << a[1] << endl;
    return 0;
  }
  ll hm = a[2];
  for(int i = 2; i < N; ++i){
    hm = min(a[i] , hm);
  }
  vector<int> ends;
  ends.push_back(1);
  for(int i = 2; i < N; ++i){
    if(a[i] == hm)
      ends.push_back(i);
  }
  ends.push_back(N);
  ll l = 0 , r = 0 , mx = -1;
  for(int i = 0; i < ends.size(); ++i){
    if(i + 1 < ends.size()) {
      ll s = sum[ends[i + 1]] - sum[ends[i] - 1] + (ll)hm * (N - (ends[i + 1] - ends[i] + 1));
      if(s > mx){
        mx = s;
        l = ends[i];
        r = ends[i + 1];
      }
    }
  }
  for(int i = 1; i < l; ++i){
    a[i] = min(a[i] , hm);
  }
  for(int i = r + 1; i <= N; ++i){
    a[i] = min(hm , a[i]);
  }
  for(int i = 1; i <= N; ++i){
    cout << a[i] << " ";
  }
  cout << endl;
}


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

const int maxn = 1e3 + 10;
ll a[maxn];
ll sum[maxn];
int N;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cin >> N;
  for(int i = 1; i <= N; ++i){
    cin >> a[i];
    sum[i] = sum[i - 1] + a[i];
  }
  if(N == 1){
    cout << a[1] << endl;
    return 0;
  }
  ll hm = a[2];
  for(int i = 2; i < N; ++i){
    hm = min(a[i] , hm);
  }
  vector<int> ends;
  ends.push_back(1);
  for(int i = 2; i < N; ++i){
    if(a[i] == hm)
      ends.push_back(i);
  }
  ends.push_back(N);
  ll l = 0 , r = 0 , mx = -1;
  for(int i = 0; i < ends.size(); ++i){
    if(i + 1 < ends.size()) {
      ll s = sum[ends[i + 1]] - sum[ends[i] - 1] + (ll)hm * (N - (ends[i + 1] - ends[i] + 1));
      if(s > mx){
        mx = s;
        l = i;
        r = i + 1;
      }
    }
  }
  for(int i = 1; i <= ends[l]; ++i){
    a[i] = min(a[i] , hm);
  }
  for(int i = ends[r] + 1; i <= N; ++i){
    a[i] = min(hm , a[i]);
  }
  for(int i = 1; i <= N; ++i){
    cout << a[i] << " ";
  }
  cout << endl;
}


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

const int maxn = 1e3 + 10;
ll a[maxn];
ll sum[maxn];
int N;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cin >> N;
  for(int i = 1; i <= N; ++i){
    cin >> a[i];
    sum[i] = sum[i - 1] + a[i];
  }
  ll hm = a[1];
  for(int i = 2; i <= N; ++i){
    hm = min(a[i] , hm);
  }
  vector<int> ends;
  ends.push_back(1);
  for(int i = 2; i <= N; ++i){
    if(a[i] == hm)
      ends.push_back(i);
  }
  if(ends.back() != N)ends.push_back(N);
  ll l , r , mx = -1;
  for(int i = 0; i < ends.size(); ++i){
    if(i + 1 < ends.size()) {
      ll s = sum[ends[i + 1]] - sum[ends[i] - 1] + (ll)hm * (N - (ends[i + 1] - ends[i] + 1));
      if(s > mx){
        mx = s;
        l = i;
        r = i + 1;
      }
    }
  }
  for(int i = 1; i < ends[l]; ++i){
    a[i] = hm;
  }
  for(int i = ends[r] + 1; i <= N; ++i){
    a[i] = hm;
  }
  for(int i = 1; i <= N; ++i){
    cout << a[i] << " ";
  }
  cout << endl;
}


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

const int maxn = 1e3 + 10;
ll a[maxn];
ll sum[maxn];
int N;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cin >> N;
  for(int i = 1; i <= N; ++i){
    cin >> a[i];
    sum[i] = sum[i - 1] + a[i];
  }
  ll hm = a[1];
  for(int i = 2; i <= N - 1; ++i){
    hm = min(a[i] , hm);
  }
  vector<int> ends;
  ends.push_back(1);
  for(int i = 2; i <= N - 1; ++i){
    if(a[i] == hm)
      ends.push_back(i);
  }
  ends.push_back(N);
  ll l , r , mx = -1;
  for(int i = 0; i < ends.size(); ++i){
    if(i + 1 < ends.size()) {
      ll s = sum[ends[i + 1]] - sum[ends[i] - 1] + (ll)hm * (N - (ends[i + 1] - ends[i] + 1));
      if(s > mx){
        mx = s;
        l = i;
        r = i + 1;
      }
    }
  }
  for(int i = 1; i < ends[l]; ++i){
    a[i] = hm;
  }
  for(int i = ends[r] + 1; i <= N; ++i){
    a[i] = hm;
  }
  for(int i = 1; i <= N; ++i){
    cout << a[i] << " ";
  }
  cout << endl;
}


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

const int maxn = 1e3 + 10;
ll a[maxn];
ll sum[maxn];
int N;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cin >> N;
  for(int i = 1; i <= N; ++i){
    cin >> a[i];
    sum[i] = sum[i - 1] + a[i];
  }
  ll hm = a[2];
  for(int i = 2; i < N; ++i){
    hm = min(a[i] , hm);
  }
  vector<int> ends;
  ends.push_back(1);
  for(int i = 2; i < N; ++i){
    if(a[i] == hm)
      ends.push_back(i);
  }
  ends.push_back(N);
  ll l = 0 , r = 0 , mx = -1;
  for(int i = 0; i < ends.size(); ++i){
    if(i + 1 < ends.size()) {
      ll s = sum[ends[i + 1]] - sum[ends[i] - 1] + (ll)hm * (N - (ends[i + 1] - ends[i] + 1));
      if(s > mx){
        mx = s;
        l = i;
        r = i + 1;
      }
    }
  }
  for(int i = 1; i < ends[l]; ++i){
    a[i] = min(a[i] , hm);
  }
  for(int i = ends[r] + 1; i <= N; ++i){
    a[i] = min(hm , a[i]);
  }
  for(int i = 1; i <= N; ++i){
    cout << a[i] << " ";
  }
  cout << endl;
}


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

const int maxn = 1e3 + 10;
ll a[maxn];
ll sum[maxn];
ll MAX[maxn][2] , MIN[maxn];
int N;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cin >> N;
  for(int i = 1; i <= N; ++i){
    cin >> a[i];
    sum[i] = sum[i - 1] + a[i];
  }
  if(N == 1){
    cout << a[1] << endl;
    return 0;
  }
  ll hm = a[2];
  for(int i = 2; i < N; ++i){
    hm = min(a[i] , hm);
  }
  vector<int> ends;
  ends.push_back(1);
  for(int i = 1; i <= N; ++i)MAX[i][0] = max(MAX[i - 1][0] , a[i]);
  for(int i = N; i >= 1; --i)MAX[i][1] = max(MAX[i + 1][1] , a[i]);
  for(int i = 2; i < N; ++i){
    if(a[i] < MAX[N - i][1] && a[i] < MAX[i][0])
      ends.push_back(i);
  }
  ends.push_back(N);
  ll l = 0 , r = 0 , mx = -1;
  for(int i = 0; i < ends.size(); ++i){
    if(i + 1 < ends.size()) {
      ll s = sum[ends[i + 1]] - sum[ends[i] - 1] + (ll)hm * (N - (ends[i + 1] - ends[i] + 1));
      if(s > mx){
        mx = s;
        l = ends[i];
        r = ends[i + 1];
      }
    }
  }
  for(int i = 1; i < l; ++i){
    a[i] = min(a[i] , hm);
  }
  for(int i = r + 1; i <= N; ++i){
    a[i] = min(hm , a[i]);
  }
  for(int i = 1; i <= N; ++i){
    cout << a[i] << " ";
  }
  cout << endl;
}


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

const int maxn = 1e3 + 10;
ll a[maxn];
ll sum[maxn];
int N;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cin >> N;
  for(int i = 1; i <= N; ++i){
    cin >> a[i];
    sum[i] = sum[i - 1] + a[i];
  }
  ll hm = a[1];
  for(int i = 2; i <= N; ++i){
    hm = min(a[i] , hm);
  }
  vector<int> ends;
  ends.push_back(1);
  for(int i = 2; i <= N; ++i){
    if(a[i] == hm)
      ends.push_back(i);
  }
  if(ends.back() != N)ends.push_back(N);
  ll l = 0 , r = 0 , mx = -1;
  for(int i = 0; i < ends.size(); ++i){
    if(i + 1 < ends.size()) {
      ll s = sum[ends[i + 1]] - sum[ends[i] - 1] + (ll)hm * (N - (ends[i + 1] - ends[i] + 1));
      if(s > mx){
        mx = s;
        l = i;
        r = i + 1;
      }
    }
  }
  for(int i = 1; i < ends[l]; ++i){
    a[i] = hm;
  }
  for(int i = ends[r] + 1; i <= N; ++i){
    a[i] = hm;
  }
  for(int i = 1; i <= N; ++i){
    cout << a[i] << " ";
  }
  cout << endl;
}


#include<bits/stdc++.h>
#include<unordered_map>
using namespace std;
#define ll long long
#define db double
#define el "\n"
#define ld long double
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
int main(){
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	#ifndef ONLINE_JUDGE
	freopen("input.txt", "r" , stdin);
	freopen("output.txt", "w" , stdout);
	#endif
	ll int n,i,j,k,tmp,flag1=0,flag2=0,count1=0,count2=0;
	//vector< pair<int,int> >q;
	vector<int> v,copy;
	cin>>n;
	for(i=0;i<n;i++){
		cin>>tmp;
		//v.pb(mp(tmp,i));
		v.pb(tmp);
	}
	// int maxx=v[0];
	// copy=v;
	//sort(copy.begin(),copy.end());
	//i=copy[n-1].ss;
	//cout<<i<<endl;
	// for(j=i+1;j<n;j++){
	// 	for(k=j+1;k<n;k++){
	// 		if(v[k].ff>v[j].ff){
	// 			v[k].ff=v[j].ff;
	// 		}
	// 	}
	// }
	// for(j=i-1;j>=0;j--){
	// 	for(k=j-1;k>=0;k--){
	// 		if(v[k].ff>v[j].ff){
	// 			v[k].ff=v[j].ff;
	// 		}
	// 	}
	// }
	// for(i=0;i<n;i++){
	// 	cout<<v[i].ff;
	// 	if(i<n-1)cout<<" ";
	// }
	// for(i=0;i<n;i++){
	// 	maxx= max(v[i],maxx);
	// 	if(maxx!=v[i]){
	// 		for(j=i-1;j>=0;j--){
	// 			if(v[j]>v[i]){
	// 				v[j]=v[i];
	// 			}
	// 		}
	// 	}
	// }
	// maxx=copy[n-1];
	// for(i=n-1;i>=0;i--){
	// 	maxx=max(copy[i],maxx);
	// 	if(maxx!=copy[i]){
	// 		for(j=i+1;j<n;j++){
	// 			if(copy[j]>copy[i]){
	// 				copy[j]=copy[i];
	// 			}
	// 		}
	// 	}
	// }
	// ll int count1=0,count2=0;
	// for(i=0;i<n;i++){
	// 	count1+=v[i];
	// 	count2+=copy[i];
	// }
	// if(count1>count2){
		// for(i=0;i<n;i++){
		// 	cout<<v[i];
		// 	if(i<n-1)cout<<" ";
		// }
	// }
	// else{
	// 	for(i=0;i<n;i++){
	// 		cout<<copy[i];
	// 		if(i<n-1)cout<<" ";
	// 	}
	// }
	for(i=1;i<n;i++){
		flag1=0;flag2=0;count1=0;count2=0;
		for(j=0;j<i;j++){
			count1+=v[j];
			if(v[j]>v[i])flag1=1;
		}
		for(j=n-1;j>i;j--){
			count2+=v[j];
			if(v[j]>v[i])flag2=1;
		}
		//cout<<flag1<<"  "<<flag2<<endl;
		if(flag1 && flag2){
			if(count1>count2){
				for(j=i+1;j<n;j++){
					if(v[j]>v[i])v[j]=v[i];
				}
			}
			else{
				for(j=i-1;j>=0;j--){
					if(v[j]>v[i])v[j]=v[i];
				}
			}
		}
	}
	for(int k=0;k<n;k++){
			cout<<v[k];
			if(k<n-1)cout<<" ";
		}
}


#include<bits/stdc++.h>
#include<unordered_map>
using namespace std;
#define ll long long
#define db double
#define el "\n"
#define ld long double
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
int main(){
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	#ifndef ONLINE_JUDGE
	freopen("input.txt", "r" , stdin);
	freopen("output.txt", "w" , stdout);
	#endif
	ll int n,i,j,k,tmp,flag1=0,flag2=0,count1=0,count2=0,no1,no2;
	//vector< pair<int,int> >q;
	vector<int> v,copy;
	cin>>n;
	for(i=0;i<n;i++){
		cin>>tmp;
		//v.pb(mp(tmp,i));
		v.pb(tmp);
	}
	// int maxx=v[0];
	// copy=v;
	//sort(copy.begin(),copy.end());
	//i=copy[n-1].ss;
	//cout<<i<<endl;
	// for(j=i+1;j<n;j++){
	// 	for(k=j+1;k<n;k++){
	// 		if(v[k].ff>v[j].ff){
	// 			v[k].ff=v[j].ff;
	// 		}
	// 	}
	// }
	// for(j=i-1;j>=0;j--){
	// 	for(k=j-1;k>=0;k--){
	// 		if(v[k].ff>v[j].ff){
	// 			v[k].ff=v[j].ff;
	// 		}
	// 	}
	// }
	// for(i=0;i<n;i++){
	// 	cout<<v[i].ff;
	// 	if(i<n-1)cout<<" ";
	// }
	// for(i=0;i<n;i++){
	// 	maxx= max(v[i],maxx);
	// 	if(maxx!=v[i]){
	// 		for(j=i-1;j>=0;j--){
	// 			if(v[j]>v[i]){
	// 				v[j]=v[i];
	// 			}
	// 		}
	// 	}
	// }
	// maxx=copy[n-1];
	// for(i=n-1;i>=0;i--){
	// 	maxx=max(copy[i],maxx);
	// 	if(maxx!=copy[i]){
	// 		for(j=i+1;j<n;j++){
	// 			if(copy[j]>copy[i]){
	// 				copy[j]=copy[i];
	// 			}
	// 		}
	// 	}
	// }
	// ll int count1=0,count2=0;
	// for(i=0;i<n;i++){
	// 	count1+=v[i];
	// 	count2+=copy[i];
	// }
	// if(count1>count2){
		// for(i=0;i<n;i++){
		// 	cout<<v[i];
		// 	if(i<n-1)cout<<" ";
		// }
	// }
	// else{
	// 	for(i=0;i<n;i++){
	// 		cout<<copy[i];
	// 		if(i<n-1)cout<<" ";
	// 	}
	// }
	for(i=1;i<n;i++){
		flag1=0;flag2=0;count1=0;count2=0;no1=0;no2=0;
		for(j=0;j<i;j++){
			//count1+=v[j];
			if(v[j]>v[i]){flag1=1;
				no1++;
				count1+=v[j];}
		}
		for(j=n-1;j>i;j--){
			//count2+=v[j];
			if(v[j]>v[i]){flag2=1;
				no2++;
				count2+=v[j];}
		}
		//cout<<flag1<<"  "<<flag2<<endl;
		if(flag1 && flag2){
			if((count1+(v[i]*no2))>(count2+(v[i]*no1))){
				for(j=i+1;j<n;j++){
					if(v[j]>v[i])v[j]=v[i];
				}
			}
			else{
				for(j=i-1;j>=0;j--){
					if(v[j]>v[i])v[j]=v[i];
				}
			}
		}
	}
	for(int k=0;k<n;k++){
			cout<<v[k];
			if(k<n-1)cout<<" ";
		}
}


#include<bits/stdc++.h>
#include<unordered_map>
using namespace std;
#define ll long long
#define db double
#define el "\n"
#define ld long double
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
int main(){
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	#ifndef ONLINE_JUDGE
	freopen("input.txt", "r" , stdin);
	freopen("output.txt", "w" , stdout);
	#endif
	ll int n,i,j,k,tmp;
	vector< pair<int,int> >v,copy;
	cin>>n;
	for(i=0;i<n;i++){
		cin>>tmp;
		v.pb(mp(tmp,i));
	}
	copy=v;
	sort(copy.begin(),copy.end());
	i=copy[n-1].ss;
	//cout<<i<<endl;
	for(j=i+1;j<n;j++){
		for(k=j+1;k<n;k++){
			if(v[k].ff>v[j].ff){
				v[k].ff=v[j].ff;
			}
		}
	}
	for(j=i-1;j>=0;j--){
		for(k=j-1;k>=0;k--){
			if(v[k].ff>v[j].ff){
				v[k].ff=v[j].ff;
			}
		}
	}
	for(i=0;i<n;i++){
		cout<<v[i].ff;
		if(i<n-1)cout<<" ";
	}
}


#include<bits/stdc++.h>
#include<unordered_map>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
using namespace std;
#define ll long long
typedef vector <ll int> vi;
typedef vector<pair<ll int,ll int> > vp;
typedef vector<vi> vvi;
typedef map<ll int,ll int> mii;
typedef pair<ll int,ll int> pii;
typedef priority_queue <ll> pq;
#define INF 1000000000
//#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define mod 1000000007
#define itr ::iterator it
#define lcm(a,b) ((a)*(b))/gcd((a),(b))
#define remin(a,b) (a) = min((a),(b))
#define remax(a,b) (a) = max((a),(b))
#define db double
#define el "\n"
#define ld long double
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
//#define fbo find_by_order
//#define ook order_of_key
struct hash_pair {
   template <class T1, class T2>
   size_t operator()(const pair<T1, T2>& p) const{
      auto hash1 = hash<T1>{}(p.first);
      auto hash2 = hash<T2>{}(p.second);
      return hash1 ^ hash2;
   }
};
ll int gcd(ll int a, ll int b){
    if(a==0){
    	return b;
    }
    if (b == 0){
       return a;
    }
    return gcd(b, a % b);
}
ll int power(ll int x,ll int n){
	ll ans=1;
     while(n>0){
         if(n&1) ans=(ans*x)%mod;
         x=(x*x)%mod;
         n/=2;
     }
     if(x==0)ans=0;
     return ans;
}
int main(){
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	#ifndef ONLINE_JUDGE
	freopen("input.txt", "r" , stdin);
	freopen("output.txt", "w" , stdout);
	#endif
	int t=1;
	//cin>>t;
	while(t--){
		int n,i,j;
		cin>>n;
		ll int a[n];
		for(i=0;i<n;i++){
			cin>>a[i];
		}
		ll int maxs=0;
		vi ans;
		for(i=0;i<n;i++){
			ll int tmp=0;
			vi tmpp(n);
			tmp+=a[i];
			tmpp[i]=a[i];
			ll int prevmax=a[i];
			for(j=i+1;j<n;j++){
				tmpp[j]=min(prevmax,a[j]);
				tmp+=tmpp[j];
				prevmax=tmpp[j];
			}
			prevmax=a[i];
			for(j=i-1;j>=0;j--){
				tmpp[j]=min(prevmax,a[j]);
				tmp+=tmpp[j];
				prevmax=tmpp[j];
			}
			if(tmp>maxs){
				maxs=tmp;
				ans=tmpp;
			}
		}
		//cout<<maxs<<endl;
		for(i=0;i<n;i++){
			cout<<ans[i]<<" ";
		}
	}
}


#include<bits/stdc++.h>
#include<unordered_map>
using namespace std;
#define ll long long
#define db double
#define el "\n"
#define ld long double
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
int main(){
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	#ifndef ONLINE_JUDGE
	freopen("input.txt", "r" , stdin);
	freopen("output.txt", "w" , stdout);
	#endif
	ll int n,i,min=pow(10,9),left,right,sumleft,sumright,total,L,R,max=0,tmp,ind;
	cin>>n;
	vector<int> v;
	for(i=0;i<n;i++){
		cin>>tmp;
		v.pb(tmp);
	}
	vector< pair<int,int> > r,l;
	for(i=0;i<n;i++){
		if(v[i]<=min){
			min=v[i];
			ind=i;
		}
		l.pb(mp(min,ind));
	}
	min=pow(10,9);
	for(i=n-1;i>=0;i--){
		if(v[i]<=min){
			min=v[i];
			ind=i;
		}
		r.pb(mp(min,ind));
	}
	reverse(r.begin(),r.end());
	vector<int> suml(n);
	vector<int> sumr(n);
	suml[0]=v[0];
	for(i=1;i<n;i++){
		suml[i]=suml[i-1]+v[i];
	}
	sumr[n-1]=v[n-1];
	for(i=n-2;i>=0;i--){
		sumr[i]=sumr[i+1]+v[i];
	}
	for(i=0;i<n;i++){
		left=0;right=0;sumright=0;sumleft=0;
		left=l[i].ff*(l[i].ss+1);
		right=r[i].ff*(n-r[i].ss);
		sumright=sumr[i]-sumr[r[i].ss]-v[i];
		//cout<<sumr[i]<<"hi "<<sumr[r[i].ss]<<endl;
		sumleft=suml[i]-suml[l[i].ss]-v[i];
		//cout<<left<<" "<<right<<" "<<sumleft<<" "<<sumright<<endl;
		total=left+right+sumright+sumleft+v[i];
		if(total>=max){
			max=total;
			L=l[i].ss;
			R=r[i].ss;
		}
	}
	for(i=0;i<=L;i++){
		cout<<v[L]<<" ";
		//if(i<L)cout<<" ";
	}
	for(i=L+1;i<R;i++){
		cout<<v[i]<<" ";
	}
	if(L!=R){
	for(i=R;i<n;i++){
		cout<<v[R];
		if(i<n-1)cout<<" ";
	}
	}
}


#include<bits/stdc++.h>
#include<unordered_map>
using namespace std;
#define ll long long
#define db double
#define el "\n"
#define ld long double
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
int main(){
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	#ifndef ONLINE_JUDGE
	freopen("input.txt", "r" , stdin);
	freopen("output.txt", "w" , stdout);
	#endif
	ll int n,i,min=pow(10,9),left,right,sumleft,sumright,total,L,R,max=0,tmp,ind;
	cin>>n;
	vector<int> v;
	for(i=0;i<n;i++){
		cin>>tmp;
		v.pb(tmp);
	}
	vector< pair<int,int> > r,l;
	for(i=0;i<n;i++){
		if(v[i]<=min){
			min=v[i];
			ind=i;
		}
		l.pb(mp(min,ind));
	}
	min=pow(10,9);
	for(i=n-1;i>=0;i--){
		if(v[i]<=min){
			min=v[i];
			ind=i;
		}
		r.pb(mp(min,ind));
	}
	reverse(r.begin(),r.end());
	vector<int> suml(n);
	vector<int> sumr(n);
	suml[0]=v[0];
	for(i=1;i<n;i++){
		suml[i]=suml[i-1]+v[i];
	}
	sumr[n-1]=v[n-1];
	for(i=n-2;i>=0;i--){
		sumr[i]=sumr[i+1]+v[i];
	}
	for(i=0;i<n;i++){
		left=0;right=0;sumright=0;sumleft=0;
		left=l[i].ff*(l[i].ss+1);
		right=r[i].ff*(n-r[i].ss);
		sumright=sumr[i]-sumr[r[i].ss]-v[i];
		//cout<<sumr[i]<<"hi "<<sumr[r[i].ss]<<endl;
		sumleft=suml[i]-suml[l[i].ss]-v[i];
		//cout<<left<<" "<<right<<" "<<sumleft<<" "<<sumright<<endl;
		total=left+right+sumright+sumleft+v[i];
		if(total>=max){
			max=total;
			L=l[i].ss;
			R=r[i].ss;
		}
	}
	for(i=0;i<=L;i++){
		cout<<v[L]<<" ";
		//if(i<L)cout<<" ";
	}
	for(i=L+1;i<R;i++){
		cout<<v[i]<<" ";
	}
	for(i=R;i<n;i++){
		cout<<v[R];
		if(i<n-1)cout<<" ";
	}
}


#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<bitset>
#include<map>
#include<cmath>
#include<set>
#include<cmath>
#include<vector>
#include<cstring>
using namespace std;
#define ll long long
#define inf 0x3f3f3f3f
#define INF 0x3f3f3f3f3f3f3f3f
const int maxn=5e5+9;
int m[maxn];
int main()
{
	int n;
	while(scanf("%d",&n)!=EOF)
	{
		int MAX=0,id=0;
		for(int i=1;i<=n;i++)
		{
			scanf("%d",&m[i]);
			if(m[i]>MAX)
			{
				MAX=m[i];
				id=i;
			}
		}
		for(int i=2;i<=id;i++)
		{
			m[i-1]=min(m[i-1],m[i]);
		}
		for(int i=id+1;i<=n;i++)
		{
			m[i]=min(m[i],m[i-1]);
		}
		for(int i=1;i<=n;i++)
		{
			if(i==1) printf("%d",m[i]);
			else printf(" %d",m[i]);
		}
		printf("\n");
	}
}


#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<bitset>
#include<map>
#include<cmath>
#include<set>
#include<cmath>
#include<vector>
#include<cstring>
using namespace std;
#define ll long long
#define inf 0x3f3f3f3f
#define INF 0x3f3f3f3f3f3f3f3f
const int maxn=5e5+9;
ll m[maxn],ans[maxn],temp[maxn];
int main()
{
	int n;
	while(scanf("%d",&n)!=EOF)
	{
		v.clear();
		for(int i=1;i<=n;i++)
		{
			scanf("%lld",&m[i]);
			temp[i]=m[i];
		}
		ll sum=0;
		for(int j=1;j<=n;j++)
		{
			ll id=j;
			for(int i=2;i<=id;i++)
			{
				m[i-1]=min(m[i-1],m[i]);
			}
			for(int i=id+1;i<=n;i++)
			{
				m[i]=min(m[i],m[i-1]);
			}
			ll x=0;
			for(int i=1;i<=n;i++)
			{
				x+=m[i];
			}
			if(x>sum)
			{
				sum=x;
				for(int i=1;i<=n;i++)
				{
					ans[i]=m[i];
				}
			}
			for(int i=1;i<=n;i++)
			{
				m[i]=temp[i];
			}
		}
		for(int i=1;i<=n;i++)
		{
			if(i==1) printf("%lld",ans[i]);
			else printf(" %lld",ans[i]);
		}
		printf("\n");
	}
}


#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<bitset>
#include<map>
#include<cmath>
#include<set>
#include<cmath>
#include<vector>
#include<cstring>
using namespace std;
#define ll long long
#define inf 0x3f3f3f3f
#define INF 0x3f3f3f3f3f3f3f3f
const int maxn=5e5+9;
ll m[maxn],ans[maxn],temp[maxn];
int main()
{
	int n;
	while(scanf("%d",&n)!=EOF)
	{
		for(int i=1;i<=n;i++)
		{
			scanf("%lld",&m[i]);
			temp[i]=m[i];
		}
		ll sum=0;
		for(int j=1;j<=n;j++)
		{
			ll id=j;
			for(int i=id;i>1;i--)
			{
				m[i-1]=min(m[i-1],m[i]);
			}
			for(int i=id+1;i<=n;i++)
			{
				m[i]=min(m[i],m[i-1]);
			}
			ll x=0;
			for(int i=1;i<=n;i++)
			{
				x+=m[i];
			}
			if(x>sum)
			{
				sum=x;
				for(int i=1;i<=n;i++)
				{
					ans[i]=m[i];
				}
			}
			for(int i=1;i<=n;i++)
			{
				m[i]=temp[i];
			}
		}
		for(int i=1;i<=n;i++)
		{
			if(i==1) printf("%lld",ans[i]);
			else printf(" %lld",ans[i]);
		}
		printf("\n");
	}
}


#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<bitset>
#include<map>
#include<cmath>
#include<set>
#include<cmath>
#include<vector>
#include<cstring>
using namespace std;
#define ll long long
#define inf 0x3f3f3f3f
#define INF 0x3f3f3f3f3f3f3f3f
const int maxn=5e5+9;
ll m[maxn],ans[maxn],temp[maxn];
int main()
{
	int n;
	while(scanf("%d",&n)!=EOF)
	{
		for(int i=1;i<=n;i++)
		{
			scanf("%lld",&m[i]);
			temp[i]=m[i];
		}
		ll sum=0;
		for(int j=1;j<=n;j++)
		{
			ll id=j;
			for(int i=2;i<=id;i++)
			{
				m[i-1]=min(m[i-1],m[i]);
			}
			for(int i=id+1;i<=n;i++)
			{
				m[i]=min(m[i],m[i-1]);
			}
			ll x=0;
			for(int i=1;i<=n;i++)
			{
				x+=m[i];
			}
			if(x>sum)
			{
				sum=x;
				for(int i=1;i<=n;i++)
				{
					ans[i]=m[i];
				}
			}
			for(int i=1;i<=n;i++)
			{
				m[i]=temp[i];
			}
		}
		for(int i=1;i<=n;i++)
		{
			if(i==1) printf("%lld",ans[i]);
			else printf(" %lld",ans[i]);
		}
		printf("\n");
	}
}


#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<bitset>
#include<map>
#include<cmath>
#include<set>
#include<cmath>
#include<vector>
#include<cstring>
using namespace std;
#define ll long long
#define inf 0x3f3f3f3f
#define INF 0x3f3f3f3f3f3f3f3f
const int maxn=5e5+9;
int m[maxn],ans[maxn],temp[maxn];
vector<int> v;
int main()
{
	int n;
	while(scanf("%d",&n)!=EOF)
	{
		int MAX=0;
		v.clear();
		for(int i=1;i<=n;i++)
		{
			scanf("%d",&m[i]);
			temp[i]=m[i];
			if(m[i]>MAX)
			{
				MAX=m[i];
			}
		}
		for(int i=1;i<=n;i++)
		{
			if(m[i]==MAX)
			{
				v.push_back(i);
			}
		}
		ll sum=0;
		for(int j=0;j<v.size();j++)
		{
			int id=v[j];
			for(int i=2;i<=id;i++)
			{
				m[i-1]=min(m[i-1],m[i]);
			}
			for(int i=id+1;i<=n;i++)
			{
				m[i]=min(m[i],m[i-1]);
			}
			ll x=0;
			for(int i=1;i<=n;i++)
			{
				x+=m[i];
			}
			if(x>sum)
			{
				sum=x;
				for(int i=1;i<=n;i++)
				{
					ans[i]=m[i];
				}
			}
			for(int i=1;i<=n;i++)
			{
				m[i]=temp[i];
			}
		}
		for(int i=1;i<=n;i++)
		{
			if(i==1) printf("%d",ans[i]);
			else printf(" %d",ans[i]);
		}
		printf("\n");
	}
}


#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<bitset>
#include<map>
#include<cmath>
#include<set>
#include<cmath>
#include<vector>
#include<cstring>
using namespace std;
#define ll long long
#define inf 0x3f3f3f3f
#define INF 0x3f3f3f3f3f3f3f3f
const int maxn=5e5+9;
int m[maxn],ans[maxn],temp[maxn];
vector<int> v;
int main()
{
	int n;
	while(scanf("%d",&n)!=EOF)
	{
		int MAX=0;
		v.clear();
		for(int i=1;i<=n;i++)
		{
			scanf("%d",&m[i]);
			temp[i]=m[i];
			if(m[i]>MAX)
			{
				MAX=m[i];
			}
		}
		for(int i=1;i<=m[i];i++)
		{
			if(m[i]==MAX)
			{
				v.push_back(i);
			}
		}
		ll sum=0;
		for(int j=0;j<v.size();j++)
		{
			int id=v[j];
			for(int i=2;i<=id;i++)
			{
				m[i-1]=min(m[i-1],m[i]);
			}
			for(int i=id+1;i<=n;i++)
			{
				m[i]=min(m[i],m[i-1]);
			}
			ll x=0;
			for(int i=1;i<=n;i++)
			{
				x+=m[i];
			}
			if(x>sum)
			{
				for(int i=1;i<=n;i++)
				{
					ans[i]=m[i];
				}
			}
			for(int i=1;i<=n;i++)
			{
				m[i]=temp[i];
			}
		}
		for(int i=1;i<=n;i++)
		{
			if(i==1) printf("%d",ans[i]);
			else printf(" %d",ans[i]);
		}
		printf("\n");
	}
}


#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<bitset>
#include<map>
#include<cmath>
#include<set>
#include<cmath>
#include<vector>
#include<cstring>
using namespace std;
#define ll long long
#define inf 0x3f3f3f3f
#define INF 0x3f3f3f3f3f3f3f3f
const int maxn=5e5+9;
ll m[maxn],ans[maxn],temp[maxn];
vector<ll> v;
int main()
{
	int n;
	while(scanf("%d",&n)!=EOF)
	{
		ll MAX=0;
		v.clear();
		for(int i=1;i<=n;i++)
		{
			scanf("%lld",&m[i]);
			temp[i]=m[i];
			if(m[i]>MAX)
			{
				MAX=m[i];
			}
		}
		for(int i=1;i<=n;i++)
		{
			if(m[i]==MAX)
			{
				v.push_back(i);
			}
		}
		ll sum=0;
		for(int j=0;j<v.size();j++)
		{
			ll id=v[j];
			for(int i=2;i<=id;i++)
			{
				m[i-1]=min(m[i-1],m[i]);
			}
			for(int i=id+1;i<=n;i++)
			{
				m[i]=min(m[i],m[i-1]);
			}
			ll x=0;
			for(int i=1;i<=n;i++)
			{
				x+=m[i];
			}
			if(x>sum)
			{
				sum=x;
				for(int i=1;i<=n;i++)
				{
					ans[i]=m[i];
				}
			}
			for(int i=1;i<=n;i++)
			{
				m[i]=temp[i];
			}
		}
		for(int i=1;i<=n;i++)
		{
			if(i==1) printf("%lld",ans[i]);
			else printf(" %lld",ans[i]);
		}
		printf("\n");
	}
}


#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<bitset>
#include<map>
#include<cmath>
#include<set>
#include<cmath>
#include<vector>
#include<cstring>
using namespace std;
#define ll long long
#define inf 0x3f3f3f3f
#define INF 0x3f3f3f3f3f3f3f3f
const int maxn=5e5+9;
int m[maxn],ans[maxn],temp[maxn];
vector<int> v;
int main()
{
	int n;
	while(scanf("%d",&n)!=EOF)
	{
		int MAX=0;
		v.clear();
		for(int i=1;i<=n;i++)
		{
			scanf("%d",&m[i]);
			temp[i]=m[i];
			if(m[i]>MAX)
			{
				MAX=m[i];
			}
		}
		for(int i=1;i<=m[i];i++)
		{
			if(m[i]==MAX)
			{
				v.push_back(i);
			}
		}
		ll sum=0;
		for(int j=0;j<v.size();j++)
		{
			int id=v[j];
			for(int i=2;i<=id;i++)
			{
				m[i-1]=min(m[i-1],m[i]);
			}
			for(int i=id+1;i<=n;i++)
			{
				m[i]=min(m[i],m[i-1]);
			}
			ll x=0;
			for(int i=1;i<=n;i++)
			{
				x+=m[i];
			}
			if(x>sum)
			{
				sum=x;
				for(int i=1;i<=n;i++)
				{
					ans[i]=m[i];
				}
			}
			for(int i=1;i<=n;i++)
			{
				m[i]=temp[i];
			}
		}
		for(int i=1;i<=n;i++)
		{
			if(i==1) printf("%d",ans[i]);
			else printf(" %d",ans[i]);
		}
		printf("\n");
	}
}


#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
  int n;
  cin>>n;ll int x;
  int a[n];int minm=100000;
  for(int i=0;i<n;i++)
  {
      cin>>a[i];
  }
  for(int i=0;i<n;i++)
  {  vector<int>v;
     vector<int>u;
    ll int sum1=0,sum2=0;int min=a[i];
      for(int j=i+1;j<n;j++)
      {
            if(min>=a[j])
                min=a[j];
          if(min<a[j])
            { //v.push_back(j);
              sum1+=a[j]-min;
            }
      }min=a[i];
      for(int j=i-1;j>=0;j--)
      {
          if(min>=a[j])
            min=a[j];
          if(min<a[j])
            { // u.push_back(j);
              sum2+=a[j]-min;
            }
      }
      if(minm>=sum1+sum2)
      {
          minm=sum1+sum2;
          x=i;
      }
  }
  int k=a[x];
  for(int i=x+1;i<n;i++)
  {
     if(a[i]>k)
        a[i]=k;
     else
        k=a[i];
  }
  k=a[x];
  for(int i=x-1;i>=0;i--)
  {
      if(a[i]>k)
        a[i]=k;
      else
        k=a[i];
  }
for(int i=0;i<n;i++)
    cout<<a[i]<<" ";
}


#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
  int n;
  cin>>n; int x;
  int a[n];int minm=100000;
  for(int i=0;i<n;i++)
  {
      cin>>a[i];
  }
  for(int i=0;i<n;i++)
  {  vector<int>v;
     vector<int>u;
    ll int sum1=0,sum2=0;int min=a[i];
      for(int j=i+1;j<n;j++)
      {
            if(min>=a[j])
                min=a[j];
          if(min<a[j])
            { //v.push_back(j);
              sum1+=a[j]-min;
            }
      }min=a[i];
      for(int j=i-1;j>=0;j--)
      {
          if(min>=a[j])
            min=a[j];
          if(min<a[j])
            { // u.push_back(j);
              sum2+=a[j]-min;
            }
      }
      if(minm>=sum1+sum2)
      {
          minm=sum1+sum2;
          x=i;
      }
  }
 ll int k=a[x];
  for(int i=x+1;i<n;i++)
  {
     if(a[i]>k)
        a[i]=k;
     else
        k=a[i];
  }
  k=a[x];
  for(int i=x-1;i>=0;i--)
  {
      if(a[i]>k)
        a[i]=k;
      else
        k=a[i];
  }
for(int i=0;i<n;i++)
    cout<<a[i]<<" ";
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n;
  cin>>n;
  int a[n];
  for(int i=0;i<n;i++)
  {
      cin>>a[i];
  }
  for(int i=1;i<n;i++)
  { vector<int>v;
    vector<int>u;int sum1=0,sum2=0;
      for(int j=i+1;j<n;j++)
      {

          if(a[i]<a[j])
            { v.push_back(j);
              sum1+=a[j]-a[i];
            }
      }
      for(int j=i-1;j>=0;j--)
      {
          if(a[i]<a[j])
            {  u.push_back(j);
              sum2+=a[j]-a[i];
            }
      }
      if(sum1>sum2)
      {
          for(int k=0;k<u.size();k++)
          {
              a[u[k]]=a[i];
          }
      }
      else
        for(int k=0;k<v.size();k++)
          {
              a[v[k]]=a[i];
          }
  }for(int i=0;i<n;i++)
  cout<<a[i]<<" ";

}


#include<bits/stdc++.h>
#definr ll long long
using namespace std;
int main()
{
  int n;
  cin>>n;ll int x;
  int a[n];int minm=100000;
  for(int i=0;i<n;i++)
  {
      cin>>a[i];
  }
  for(int i=0;i<n;i++)
  {  vector<int>v;
     vector<int>u;
    ll int sum1=0,sum2=0;int min=a[i];
      for(int j=i+1;j<n;j++)
      {
            if(min>=a[j])
                min=a[j];
          if(min<a[j])
            { //v.push_back(j);
              sum1+=a[j]-min;
            }
      }min=a[i];
      for(int j=i-1;j>=0;j--)
      {
          if(min>=a[j])
            min=a[j];
          if(min<a[j])
            { // u.push_back(j);
              sum2+=a[j]-min;
            }
      }
      if(minm>=sum1+sum2)
      {
          minm=sum1+sum2;
          x=i;
      }
  }
  int k=a[x];
  for(int i=x+1;i<n;i++)
  {
     if(a[i]>k)
        a[i]=k;
     else
        k=a[i];
  }
  k=a[x];
  for(int i=x-1;i>=0;i--)
  {
      if(a[i]>k)
        a[i]=k;
      else
        k=a[i];
  }
for(int i=0;i<n;i++)
    cout<<a[i]<<" ";
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n;
  cin>>n;int x;
  int a[n];int minm=100000;
  for(int i=0;i<n;i++)
  {
      cin>>a[i];
  }
  for(int i=0;i<n;i++)
  {  vector<int>v;
     vector<int>u;
    int sum1=0,sum2=0;int min=a[i];
      for(int j=i+1;j<n;j++)
      {
            if(min>=a[j])
                min=a[j];
          if(min<a[j])
            { //v.push_back(j);
              sum1+=a[j]-min;
            }
      }min=a[i];
      for(int j=i-1;j>=0;j--)
      {
          if(min>=a[j])
            min=a[j];
          if(min<a[j])
            { // u.push_back(j);
              sum2+=a[j]-min;
            }
      }
      if(minm>=sum1+sum2)
      {
          minm=sum1+sum2;
          x=i;
      }
  }
  int k=a[x];
  for(int i=x+1;i<n;i++)
  {
     if(a[i]>k)
        a[i]=k;
     else
        k=a[i];
  }
  k=a[x];
  for(int i=x-1;i>=0;i--)
  {
      if(a[i]>k)
        a[i]=k;
      else
        k=a[i];
  }
for(int i=0;i<n;i++)
    cout<<a[i]<<" ";
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n;
  cin>>n;
  int a[n];
  for(int i=0;i<n;i++)
  {
      cin>>a[i];
  }
  for(int i=0;i<n;i++)
  { vector<int>v;
    vector<int>u;int sum1=0,sum2=0;
      for(int j=i+1;j<n;j++)
      {

          if(a[i]<a[j])
            { v.push_back(j);
              sum1+=a[j]-a[i];
            }
      }
      for(int j=i-1;j>=0;j--)
      {
          if(a[i]<a[j])
            {  u.push_back(j);
              sum2+=a[j]-a[i];
            }
      }
      if(sum1>sum2)
      {
          for(int k=0;k<u.size();k++)
          {
              a[u[k]]=a[i];
          }
      }
      else
        for(int k=0;k<v.size();k++)
          {
              a[v[k]]=a[i];
          }
  }for(int i=0;i<n;i++)
  cout<<a[i]<<" ";

}


#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
  int n;
  cin>>n; int x;
  ll int a[n];ll int minm=100000;
  for(int i=0;i<n;i++)
  {
      cin>>a[i];
  }
  for(int i=0;i<n;i++)
  {  vector<int>v;
     vector<int>u;
    ll int sum1=0,sum2=0;ll int min=a[i];
      for(int j=i+1;j<n;j++)
      {
            if(min>=a[j])
                min=a[j];
          if(min<a[j])
            { //v.push_back(j);
              sum1+=a[j]-min;
            }
      }min=a[i];
      for(int j=i-1;j>=0;j--)
      {
          if(min>=a[j])
            min=a[j];
          if(min<a[j])
            { // u.push_back(j);
              sum2+=a[j]-min;
            }
      }
      if(minm>=sum1+sum2)
      {
          minm=sum1+sum2;
          x=i;
      }
  }
 ll int k=a[x];
  for(int i=x+1;i<n;i++)
  {
     if(a[i]>k)
        a[i]=k;
     else
        k=a[i];
  }
  k=a[x];
  for(int i=x-1;i>=0;i--)
  {
      if(a[i]>k)
        a[i]=k;
      else
        k=a[i];
  }
for(int i=0;i<n;i++)
    cout<<a[i]<<" ";
}


#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
  int n;
  cin>>n; int x;
  ll a[n],minm=1e18,min1=1e18;
  for(int i=0;i<n;i++)
  {
      cin>>a[i];
  }
  for(int i=0;i<n;i++)
  {
    ll sum1=0,sum2=0;min1=a[i];
      for(int j=i+1;j<n;j++)
      {
            if(min1>=a[j])
                min1=a[j];
          if(min1<a[j])
            {
              sum1+=a[j]-min1;
            }
      }min1=a[i];
      for(int j=i-1;j>=0;j--)
      {
          if(min1>=a[j])
            min1=a[j];
          if(min1<a[j])
            {
              sum2+=a[j]-min1;
            }
      }
      if(minm>=sum1+sum2)
      {
          minm=sum1+sum2;
          x=i;
      }
  }
ll k=a[x];
  for(int i=x+1;i<n;i++)
  {
     if(a[i]>k)
        a[i]=k;
     else
        k=a[i];
  }
  k=a[x];
  for(int i=x-1;i>=0;i--)
  {
      if(a[i]>k)
        a[i]=k;
      else
        k=a[i];
  }
for(int i=0;i<n;i++)
    cout<<a[i]<<" ";
}


#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
  int n;
  cin>>n; int x;
  ll a[n],minm=10e10,min1=10e10;
  for(int i=0;i<n;i++)
  {
      cin>>a[i];
  }
  for(int i=0;i<n;i++)
  {
    ll sum1=0,sum2=0;min1=a[i];
      for(int j=i+1;j<n;j++)
      {
            if(min1>=a[j])
                min1=a[j];
          if(min1<a[j])
            {
              sum1+=a[j]-min1;
            }
      }min1=a[i];
      for(int j=i-1;j>=0;j--)
      {
          if(min1>=a[j])
            min1=a[j];
          if(min1<a[j])
            {
              sum2+=a[j]-min1;
            }
      }
      if(minm>=sum1+sum2)
      {
          minm=sum1+sum2;
          x=i;
      }
  }
ll k=a[x];
  for(int i=x+1;i<n;i++)
  {
     if(a[i]>k)
        a[i]=k;
     else
        k=a[i];
  }
  k=a[x];
  for(int i=x-1;i>=0;i--)
  {
      if(a[i]>k)
        a[i]=k;
      else
        k=a[i];
  }
for(int i=0;i<n;i++)
    cout<<a[i]<<" ";
}


#include<bits/stdc++.h>
#define inti long long
using namespace std;
int main()
{
  inti n;
  cin>>n; inti x;
  inti a[n]; inti minm=10000000;
  for(int i=0;i<n;i++)
  {
      cin>>a[i];
  }
  for(int i=0;i<n;i++)
  {
    inti sum1=0,sum2=0; inti min=a[i];
      for(int j=i+1;j<n;j++)
      {
            if(min>=a[j])
                min=a[j];
          if(min<a[j])
            { //v.push_back(j);
              sum1+=a[j]-min;
            }
      }min=a[i];
      for(int j=i-1;j>=0;j--)
      {
          if(min>=a[j])
            min=a[j];
          if(min<a[j])
            { // u.push_back(j);
              sum2+=a[j]-min;
            }
      }
      if(minm>=sum1+sum2)
      {
          minm=sum1+sum2;
          x=i;
      }
  }
inti k=a[x];
  for(int i=x+1;i<n;i++)
  {
     if(a[i]>k)
        a[i]=k;
     else
        k=a[i];
  }
  k=a[x];
  for(int i=x-1;i>=0;i--)
  {
      if(a[i]>k)
        a[i]=k;
      else
        k=a[i];
  }
for(int i=0;i<n;i++)
    cout<<a[i]<<" ";
}


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

int main(){
    int n;
    cin>>n;
    long ans,final_ans;
    long pre,m[n],maxi,a[n],store[n];
    for(int i=0;i<n;i++){
        cin>>m[i];
    }
    final_ans=0;
    for(int i=0;i<n;i++){
        ans=0;
        pre=m[i];
        for(int j=i;j>=0;j--){
            pre=min(pre,m[j]);
            store[j]=pre;
            ans=ans+pre;
        }
        pre=m[i];
        for(int j=i;j<n;j++){
            pre=min(pre,m[j]);
            store[j]=pre;
            ans=ans+pre;
        }
        if(ans>final_ans){
            final_ans=ans;
            for(int j=0;j<n;j++){
                a[j]=store[j];
            }
        }
    }
    for(int i=0;i<n;i++){
        cout<<a[i]<<" ";
    }
    cout<<"\n";
    return 0;
}


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

int main(){
    int n;
    scanf("%d",&n);
    long long ans,final_ans;
    long long pre,m[n],maxi,a[n],store[n];
    for(int i=0;i<n;i++){
        scanf("%ld",&m[i]);
    }
    final_ans=0;
    for(int i=0;i<n;i++){
        ans=0;
        pre=m[i];
        for(int j=i;j>=0;j--){
            pre=min(pre,m[j]);
            store[j]=pre;
            ans=ans+pre;
        }
        pre=m[i];
        for(int j=i;j<n;j++){
            pre=min(pre,m[j]);
            store[j]=pre;
            ans=ans+pre;
        }
        pre=m[i];
        if(ans>final_ans){
            final_ans=ans;
            for(int j=0;j<n;j++){
                a[j]=store[j];
            }
        }
    }
    for(int i=0;i<n;i++){
        cout<<a[i]<<" ";
    }
    cout<<"\n";
    return 0;
}


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

int main(){
    int n;
    cin>>n;
    long long ans,final_ans;
    long pre,m[n],maxi,a[n],store[n];
    for(int i=0;i<n;i++){
        cin>>m[i];
    }
    final_ans=0;
    for(int i=0;i<n;i++){
        ans=0;
        pre=m[i];
        for(int j=i;j>=0;j--){
            pre=min(pre,m[j]);
            store[j]=pre;
            ans=ans+pre;
        }
        pre=m[i];
        for(int j=i;j<n;j++){
            pre=min(pre,m[j]);
            store[j]=pre;
            ans=ans+pre;
        }
        if(ans>final_ans){
            final_ans=ans;
            for(int j=0;j<n;j++){
                a[j]=store[j];
            }
        }
    }
    for(int i=0;i<n;i++){
        cout<<a[i]<<" ";
    }
    cout<<"\n";
    return 0;
}


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

int main(){
    int n;
    scanf("%d",&n);
    long long ans,final_ans;
    long long pre,m[n],maxi,a[n],store[n];
    for(int i=0;i<n;i++){
        scanf("%lld",&m[i]);
    }
    final_ans=0;
    for(int i=0;i<n;i++){
        ans=0;
        pre=m[i];
        for(int j=i;j>=0;j--){
            pre=min(pre,m[j]);
            store[j]=pre;
            ans=ans+pre;
        }
        pre=m[i];
        for(int j=i;j<n;j++){
            pre=min(pre,m[j]);
            store[j]=pre;
            ans=ans+pre;
        }
        pre=m[i];
        if(ans>final_ans){
            final_ans=ans;
            for(int j=0;j<n;j++){
                a[j]=store[j];
            }
        }
    }
    for(int i=0;i<n;i++){
        cout<<a[i]<<" ";
    }
    cout<<"\n";
    return 0;
}


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

int main(){
    int n;
    scanf("%d",&n);
    long long ans,final_ans;
    long pre,m[n],maxi,a[n],store[n];
    for(int i=0;i<n;i++){
        scanf("%ld",&m[i]);
    }
    final_ans=0;
    for(int i=0;i<n;i++){
        ans=0;
        pre=m[i];
        for(int j=i;j>=0;j--){
            pre=min(pre,m[j]);
            store[j]=pre;
            ans=ans+pre;
        }
        pre=m[i];
        for(int j=i;j<n;j++){
            pre=min(pre,m[j]);
            store[j]=pre;
            ans=ans+pre;
        }
        pre=m[i];
        if(ans>final_ans){
            final_ans=ans;
            for(int j=0;j<n;j++){
                a[j]=store[j];
            }
        }
    }
    for(int i=0;i<n;i++){
        cout<<a[i]<<" ";
    }
    cout<<"\n";
    return 0;
}


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

int main(){
    int n;
    cin>>n;
    long pre,m[n],maxi,final_ans,ans,a[n],store[n];
    for(int i=0;i<n;i++){
        cin>>m[i];
    }
    final_ans=0;
    for(int i=0;i<n;i++){
        maxi=m[i];
        ans=0;
        pre=m[i];
        for(int j=i;j>=0;j--){
            pre=min(pre,m[j]);
            store[j]=pre;
            ans=ans+pre;
        }
        pre=m[i];
        for(int j=i;j<n;j++){
            pre=min(pre,m[j]);
            store[j]=pre;
            ans=ans+pre;
        }
        if(ans>final_ans){
            final_ans=ans;
            for(int j=0;j<n;j++){
                a[j]=store[j];
            }
        }
    }
    for(int i=0;i<n;i++){
        cout<<a[i]<<" ";
    }
    cout<<"\n";
}


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

int main(){
    int n;
    scanf("%d",&n);
    long long ans,final_ans;
    long long pre,m[n],maxi,a[n],store[n];
    for(int i=0;i<n;i++){
        scanf("%lld",&m[i]);
    }
    final_ans=0;
    for(int i=0;i<n;i++){
        ans=0;
        pre=m[i];
        ans=ans-pre;
        for(int j=i;j>=0;j--){
            pre=min(pre,m[j]);
            store[j]=pre;
            ans=ans+pre;
        }
        pre=m[i];
        for(int j=i;j<n;j++){
            pre=min(pre,m[j]);
            store[j]=pre;
            ans=ans+pre;
        }
        pre=m[i];
        if(ans>final_ans){
            final_ans=ans;
            for(int j=0;j<n;j++){
                a[j]=store[j];
            }
        }
    }
    for(int i=0;i<n;i++){
        cout<<a[i]<<" ";
    }
    cout<<"\n";
    return 0;
}


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

#define ull unsigned long long int
#define ll long long int
#define pb push_back
#define MOD (ull)(double)(1e9 + 7)
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pull pair<ull, ull>
#define m_p make_pair

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

	int n;
	cin >> n;

	ll m[n];
	for(int i=0;i<n;i++)cin >> m[i];

	vector<ll> ans;
	ans.pb(m[0]);
	int i=1;
	while(i<n && m[i] >= m[i-1])ans.pb(m[i++]);
	while(i<n && m[i] <= m[i-1])ans.pb(m[i++]);
	int x = ans[ans.size()-1];
	while(i<n){
		ans.pb(x);i++;
	}
	vector<ll> ans2;
	i=n-2;
	ans2.pb(m[n-1]);
	while(i>=0 && m[i] >= m[i+1])ans2.pb(m[i--]);
	while(i>=0 && m[i] <= m[i+1])ans2.pb(m[i--]);
	x = ans2[ans2.size()-1];
	while(i>=0){
		ans2.pb(x);
		i--;
	}
	reverse(ans2.begin(), ans2.end());
	ll one = accumulate(ans.begin(), ans.end(), 0);
	ll two = accumulate(ans2.begin(), ans2.end(), 0);
	if(one > two)
	for(i=0;i<n;i++)cout << ans[i] << " ";
	else
	for(i=0;i<n;i++)cout << ans2[i] << " ";
}


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

#define ull unsigned long long int
#define ll long long int
#define pb push_back
#define MOD (ull)(double)(1e9 + 7)
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pull pair<ull, ull>
#define m_p make_pair

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

	ll n;
	cin >> n;

	ll m[n];
	for(int i=0;i<n;i++)cin >> m[i];

	vector<ll> ans;
	ll sum=0;
	for(int i=0 ; i<n ; ++i){
		ll t=m[i];
		vector<ll> v(n);
		v[i] = t;
		for(int j=i-1 ; j>=0 ; --j){
			t = min(t, m[j]);
			v[j] = t;
		}
		t = m[i];
		for(int j=i+1 ; j<n ; ++j){
			t = min(t, m[j]);
			v[j] = t;
		}
		ll s = accumulate(v.begin(), v.end(), 0ll);
		if(s > sum){
			sum = s;
			ans = v;
		}
	}

	for(auto i : ans)cout << i << " ";
}


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

#define ull unsigned long long int
#define ll long long int
#define pb push_back
#define MOD (ull)(double)(1e9 + 7)
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pull pair<ull, ull>
#define m_p make_pair

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

	int n;
	cin >> n;

	ll m[n];
	for(int i=0;i<n;i++)cin >> m[i];

	vector<ll> ans;
	ans.pb(m[0]);
	int i=1;
	while(i<n && m[i] >= m[i-1])ans.pb(m[i++]);
	while(i<n && m[i] <= m[i-1])ans.pb(m[i++]);
	int x = ans[ans.size()-1];
	while(i<n){
		ans.pb(x);i++;
	}
	vector<ll> ans2;
	i=n-2;
	ans.pb(m[n-1]);
	while(i>0 && m[i] >= m[i+1])ans2.pb(m[i--]);
	while(i>0 && m[i] <= m[i+1])ans2.pb(m[i--]);
	x = ans2[ans2.size()-1];
	while(i>0){
		ans2.pb(x);
		i--;
	}
	reverse(ans2.begin(), ans2.end());
	ll one = accumulate(ans.begin(), ans.end(), 0);
	ll two = accumulate(ans2.begin(), ans2.end(), 0);
	if(one > two)
	for(i=0;i<n;i++)cout << ans[i] << " ";
	else
	for(i=0;i<n;i++)cout << ans2[i] << " ";
}


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

#define ull unsigned long long int
#define ll long long int
#define pb push_back
#define MOD (ull)(double)(1e9 + 7)
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pull pair<ull, ull>
#define m_p make_pair

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

	ll n;
	cin >> n;

	ll m[n];
	for(int i=0;i<n;i++)cin >> m[i];

	vector<ll> ans;
	ll sum=0;
	for(int i=0 ; i<n ; ++i){
		ll t=m[i];
		vector<ll> v(n);
		v[i] = t;
		for(int j=i-1 ; j>=0 ; --j){
			t = min(t, m[j]);
			v[j] = t;
		}
		t = m[i];
		for(int j=i+1 ; j<n ; ++j){
			t = min(t, m[j]);
			v[j] = t;
		}
		ll s = accumulate(v.begin(), v.end(), 0);
		if(s > sum){
			sum = s;
			ans = v;
		}
	}

	for(auto i : ans)cout << i << " ";
}


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

#define ull unsigned long long int
#define ll long long int
#define pb push_back
#define MOD (ull)(double)(1e9 + 7)
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pull pair<ull, ull>
#define m_p make_pair

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

	int n;
	cin >> n;

	int m[n];
	for(int i=0;i<n;i++)cin >> m[i];

	vector<int> ans;
	ans.pb(m[0]);
	int i=1;
	while(i<n && m[i] >= m[i-1])ans.pb(m[i++]);
	while(i<n && m[i] <= m[i-1])ans.pb(m[i++]);
	int x = ans[ans.size()-1];
	while(i<n){
		ans.pb(x);i++;
	}

	for(i=0;i<n;i++)cout << ans[i] << " ";
}


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

#define ull unsigned long long int
#define ll long long int
#define pb push_back
#define MOD (ull)(double)(1e9 + 7)
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pull pair<ull, ull>
#define m_p make_pair

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

	ll n;
	cin >> n;

	ll m[n];
	for(int i=0;i<n;i++)cin >> m[i];

	vector<ll> ans;
	ans.pb(m[0]);
	int i=1;
	while(i<n && m[i] >= m[i-1])ans.pb(m[i++]);
	while(i<n && m[i] <= m[i-1])ans.pb(m[i++]);
	int x = ans[ans.size()-1];
	while(i<n){
		ans.pb(x);i++;
	}

	vector<ll> ans2;
	i=n-2;
	ans2.pb(m[n-1]);
	while(i>=0 && m[i] >= m[i+1])ans2.pb(m[i--]);
	while(i>=0 && m[i] <= m[i+1])ans2.pb(m[i--]);
	x = ans2[ans2.size()-1];
	while(i>=0){
		ans2.pb(x);
		i--;
	}

	for(int i=0 ; i<n ; ++i)ans[i] = min(ans[i], m[i]);

	reverse(ans2.begin(), ans2.end());

	for(int i=0 ; i<n ; ++i)ans2[i] = min(ans2[i], m[i]);

	ll one = accumulate(ans.begin(), ans.end(), 0);
	ll two = accumulate(ans2.begin(), ans2.end(), 0);

	if(one > two)
		for(i=0;i<n;i++)cout << ans[i] << " ";
	else
		for(i=0 ; i<n ; ++i)cout << ans2[i] << " ";
}


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

#define ull unsigned long long int
#define ll long long int
#define pb push_back
#define MOD (ull)(double)(1e9 + 7)
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pull pair<ull, ull>
#define m_p make_pair

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

	ll n;
	cin >> n;

	ll m[n];
	for(int i=0;i<n;i++)cin >> m[i];

	vector<ll> ans;
	ans.pb(m[0]);
	int i=1;
	while(i<n && m[i] >= m[i-1])ans.pb(m[i++]);
	while(i<n && m[i] <= m[i-1])ans.pb(m[i++]);
	int x = ans[ans.size()-1];
	while(i<n){
		ans.pb(x);i++;
	}

	vector<ll> ans2;
	i=n-2;
	ans2.pb(m[n-1]);
	while(i>=0 && m[i] >= m[i+1])ans2.pb(m[i--]);
	while(i>=0 && m[i] <= m[i+1])ans2.pb(m[i--]);
	x = ans2[ans2.size()-1];
	while(i>=0){
		ans2.pb(x);
		i--;
	}

	ll one = 0;
	for(i=0;i<n;i++)one += ans[i];
	ll two = 0;
	for(i=0;i<n;i++)two += ans2[i];

	if(one > two)
		for(i=0;i<n;i++)cout << ans[i] << " ";
	else
		for(i=n-1;i>=0;i--)cout << ans2[i] << " ";
}


#include <bits/stdc++.h>
using namespace std;
int main()
{
	long long int mi=1000000000000000000,j,i,cost;
	int n;
	scanf("%lld",&n);
	int ara[n],ara2[n],ara3[n][n],am[n];
	for(i=0;i<n;i++){
		scanf("%d",&ara[i]);
		ara2[i]=ara[i];
	}
	for(i=0;i<n;i++){
		cost=0;
		ara3[i][i]=ara[i];
		for(j=i;j>=1;j--){
			if(ara[j]<ara[j-1]){
				cost+=ara[j-1]-ara[j];
				ara[j]-=ara[j-1]-ara[j];
			}
			ara3[i][j]=ara[j-1];
		}
		for(j=i;j<n-1;j++){
			if(ara[j+1]>ara[j]){
				cost+=ara[j+1]-ara[j];
				ara[j+1]-=ara[j+1]-ara[j];

			}
			ara3[i][j+1]=ara[j+1];
		}
		am[i]=cost;
		mi=min(mi,cost);
		for(j=0;j<n;j++){
			ara[j]=ara2[j];
		}
	}
	for(i=n;i>=0;i--){
		if(am[i]==mi){
			for(j=0;j<n;j++){
				printf("%d ",ara3[i][j]);
			}
			break;
		}
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main()
{
	long long int mi=1000000000000000000,j,i,cost;
	int n;
	scanf("%lld",&n);
	long long int ara[n],ara2[n],ara3[n][n],am[n];
	for(i=0;i<n;i++){
		scanf("%lld",&ara[i]);
		ara2[i]=ara[i];
	}
	for(i=0;i<n;i++){
		cost=0;
		ara3[i][i]=ara[i];
		for(j=i-1;j>=0;j--){
			if(ara[j]>ara[j+1]){
				cost+=ara[j]-ara[j+1];
				ara[j]-=ara[j]-ara[j+1];
			}
			ara3[i][j]=ara[j];
		}
		for(j=i;j<n-1;j++){
			if(ara[j+1]>ara[j]){
				cost+=ara[j+1]-ara[j];
				ara[j+1]-=ara[j+1]-ara[j];

			}
			ara3[i][j+1]=ara[j+1];
		}
		am[i]=cost;
		mi=min(mi,cost);
		for(j=0;j<n;j++){
			ara[j]=ara2[j];
		}
	}
	for(i=n;i>=0;i--){
		if(am[i]==mi){
			for(j=0;j<n;j++){
				printf("%lld ",ara3[i][j]);
			}
			break;
		}
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main()
{
	long long int mi=1000000000000000000,j,i,cost,n;
	scanf("%lld",&n);
	long long int ara[n],ara2[n],ara3[n][n],am[n];
	for(i=0;i<n;i++){
		scanf("%lld",&ara[i]);
		ara2[i]=ara[i];
	}
	for(i=0;i<n;i++){
		cost=0;
		ara3[i][i]=ara[i];
		for(j=i-1;j>=0;j--){
			if(ara[j]>ara[j+1]){
				cost+=ara[j]-ara[j+1];
				ara[j]-=ara[j]-ara[j+1];
			}
			ara3[i][j]=ara[j];
		}
		for(j=i;j<n-1;j++){
			if(ara[j+1]>ara[j]){
				cost+=ara[j+1]-ara[j];
				ara[j+1]-=ara[j+1]-ara[j];

			}
			ara3[i][j+1]=ara[j+1];
		}
		am[i]=cost;
		mi=min(mi,cost);
		for(j=0;j<n;j++){
			ara[j]=ara2[j];
		}
	}
	for(i=n-1;i>=0;i--){
		if(am[i]==mi){
			for(j=0;j<n;j++){
				printf("%lld ",ara3[i][j]);
			}
			break;
		}
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main()
{
	long long int mi=INT_MAX,j,i,n,cost;
	scanf("%lld",&n);
	int ara[n],ara2[n],ara3[n][n],am[n];
	for(i=0;i<n;i++){
		scanf("%d",&ara[i]);
		ara2[i]=ara[i];
	}
	for(i=0;i<n;i++){
		cost=0;
		ara3[i][i]=ara[i];
		for(j=i-1;j>=0;j--){
			if(ara[j]>ara[j+1]){
				cost+=ara[j]-ara[j+1];
				ara[j]-=ara[j]-ara[j+1];
			}
			ara3[i][j]=ara[j];
		}
		for(j=i;j<n-1;j++){
			if(ara[j+1]>ara[j]){
				cost+=ara[j+1]-ara[j];
				ara[j+1]-=ara[j+1]-ara[j];
			}
			ara3[i][j+1]=ara[j+1];
		}
		am[i]=cost;
		mi=min(mi,cost);
		for(j=0;j<n;j++){
			ara[j]=ara2[j];
		}
	}
	for(i=0;i<n;i++){
		if(am[i]==mi){
			for(j=0;j<n;j++){
				printf("%d ",ara3[i][j]);
			}
			break;
		}
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main()
{
	long long int mi=100000000000000000,j,i,n,cost;
	scanf("%lld",&n);
	int ara[n],ara2[n],ara3[n][n],am[n];
	for(i=0;i<n;i++){
		scanf("%d",&ara[i]);
		ara2[i]=ara[i];
	}
	for(i=0;i<n;i++){
		cost=0;
		ara3[i][i]=ara[i];
		for(j=i-1;j>=0;j--){
			if(ara[j]>ara[j+1]){
				cost+=ara[j]-ara[j+1];
				ara[j]-=ara[j]-ara[j+1];
			}
			ara3[i][j]=ara[j];
		}
		for(j=i;j<n-1;j++){
			if(ara[j+1]>ara[j]){
				cost+=ara[j+1]-ara[j];
				ara[j+1]-=ara[j+1]-ara[j];
			}
			ara3[i][j+1]=ara[j+1];
		}
		am[i]=cost;
		mi=min(mi,cost);
		for(j=0;j<n;j++){
			ara[j]=ara2[j];
		}
	}
	for(i=0;i<n;i++){
		if(am[i]==mi){
			for(j=0;j<n;j++){
				printf("%d ",ara3[i][j]);
			}
			break;
		}
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main()
{
    long long int mi=100000000000000000,j,i,n,cost;
    scanf("%lld",&n);
    int ara[n],ara2[n],ara3[n][n],am[n];
    for(i=0;i<n;i++){
        scanf("%d",&ara[i]);
        ara2[i]=ara[i];
    }
    sort(ara2,ara2+n);
    for(i=0;i<n;i++){
        if(ara[i]==ara2[n-1]){
            j=i;
            break;
        }
    }
    for(i=j;i<n-1;i++){
        if(ara[i+1]>ara[i]){
            ara[i+1]-=ara[i+1]-ara[i];
        }
    }
    for(i=j-1;i>=0;i--){
        if(ara[i]>ara[i+1]){
            ara[i]-=ara[i]-ara[i+1];
        }
    }
    for(i=0;i<n;i++){
        printf("%d ",ara[i]);
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main()
{
	long long int mi=1000000000000000000,j,i,cost;
	int n;
	scanf("%lld",&n);
	int ara[n],ara2[n],ara3[n][n],am[n];
	for(i=0;i<n;i++){
		scanf("%d",&ara[i]);
		ara2[i]=ara[i];
	}
	for(i=0;i<n;i++){
		cost=0;
		ara3[i][i]=ara[i];
		for(j=i-1;j>=0;j--){
			if(ara[j]>ara[j+1]){
				cost+=ara[j]-ara[j+1];
				ara[j]-=ara[j]-ara[j+1];
			}
			ara3[i][j]=ara[j];
		}
		for(j=i;j<n-1;j++){
			if(ara[j+1]>ara[j]){
				cost+=ara[j+1]-ara[j];
				ara[j+1]-=ara[j+1]-ara[j];
			}
			ara3[i][j+1]=ara[j+1];
		}
		am[i]=cost;
		mi=min(mi,cost);
		for(j=0;j<n;j++){
			ara[j]=ara2[j];
		}
	}
	for(i=0;i<n;i++){
		if(am[i]==mi){
			for(j=0;j<n;j++){
				printf("%d ",ara3[i][j]);
			}
			break;
		}
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main()
{
	long long int mi=1000000000000000000,j,i,cost;
	int n;
	scanf("%lld",&n);
	int ara[n],ara2[n],ara3[n][n],am[n];
	for(i=0;i<n;i++){
		scanf("%d",&ara[i]);
		ara2[i]=ara[i];
	}
	for(i=0;i<n;i++){
		cost=0;
		ara3[i][i]=ara[i];
		for(j=i-1;j>=0;j--){
			if(ara[j]>ara[j+1]){
				cost+=ara[j]-ara[j+1];
				ara[j]-=ara[j]-ara[j+1];
			}
			ara3[i][j]=ara[j];
		}
		for(j=i;j<n-1;j++){
			if(ara[j+1]>ara[j]){
				cost+=ara[j+1]-ara[j];
				ara[j+1]-=ara[j+1]-ara[j];
			}
			ara3[i][j+1]=ara[j+1];
		}
		am[i]=cost;
		mi=min(mi,cost);
		for(j=0;j<n;j++){
			ara[j]=ara2[j];
		}
	}
	for(i=n;i>=0;i--){
		if(am[i]==mi){
			for(j=0;j<n;j++){
				printf("%d ",ara3[i][j]);
			}
			break;
		}
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main()
{
	long long int mi=1000000000000000000,j,i,cost,n;
	scanf("%lld",&n);
	long long int ara[n],ara2[n],ara3[n][n],am[n];
	for(i=0;i<n;i++){
		scanf("%lld",&ara[i]);
		ara2[i]=ara[i];
	}
	for(i=0;i<n;i++){
		cost=0;
		ara3[i][i]=ara[i];
		for(j=i-1;j>=0;j--){
			if(ara[j]>ara[j+1]){
				cost+=ara[j]-ara[j+1];
				ara[j]-=ara[j]-ara[j+1];
			}
			ara3[i][j]=ara[j];
		}
		for(j=i;j<n-1;j++){
			if(ara[j+1]>ara[j]){
				cost+=ara[j+1]-ara[j];
				ara[j+1]-=ara[j+1]-ara[j];

			}
			ara3[i][j+1]=ara[j+1];
		}
		am[i]=cost;
		mi=min(mi,cost);
		for(j=0;j<n;j++){
			ara[j]=ara2[j];
		}
	}
	for(i=n;i>=0;i--){
		if(am[i]==mi){
			for(j=0;j<n;j++){
				printf("%lld ",ara3[i][j]);
			}
			break;
		}
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main()
{
	long long int mi=1000000000000000000,j,i,cost;
	int n;
	scanf("%lld",&n);
	long long int ara[n],ara2[n],ara3[n][n],am[n];
	for(i=0;i<n;i++){
		scanf("%lld",&ara[i]);
		ara2[i]=ara[i];
	}
	for(i=0;i<n;i++){
		cost=0;
		ara3[i][i]=ara[i];
		for(j=i-1;j>=0;j--){
			if(ara[j]>ara[j+1]){
				cost+=ara[j]-ara[j+1];
				ara[j]-=ara[j]-ara[j+1];
			}
			ara3[i][j]=ara[j];
		}
		for(j=i;j<n-1;j++){
			if(ara[j+1]>ara[j]){
				cost+=ara[j+1]-ara[j];
				ara[j+1]-=ara[j+1]-ara[j];

			}
			ara3[i][j+1]=ara[j+1];
		}
		am[i]=cost;
		mi=min(mi,cost);
		for(j=0;j<n;j++){
			ara[j]=ara2[j];
		}
	}
	for(i=n;i>=0;i--){
		if(am[i]==mi){
			for(j=0;j<n;j++){
				printf("%d ",ara3[i][j]);
			}
			break;
		}
	}
	return 0;
}


// never underestimate the laziness and freetime

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const ll X = 2e6;
const ll inf = 1e9 + 7ll;
#define pr(x)               printf("%lld", x)
#define in(x)               scanf("%lld", &x)
#define all(x)              x.begin(), x.end()
#define le(x)               cout << #x << ' ' << x << '\n'
#define xd                  cout << '\n'
#define fi                  first
#define se                  second
#define pb                  push_back
#define vi                  vector<ll>
#define show(x)             cout << #x << " : "; for(auto i : x) cout << i << ' '; xd
#define Google              ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define Code()              Google;  int T; cin >> T; while(T-- )
#define loop(i, a, b)       for(int i = a; i < b; ++i )
#define rep(i, a, b)        for(int i = b - 1; i >= a; --i)
#define inx(a, n)           loop(i, 0, n) cin >> a[i]
#define prx(a, n)           loop(i, 0, n) cout << a[i] << ' ';
int main()
{
        Google;

        // logic :: go for i'th element , update a/c for that on both sides
        // get such max a at index I , print that I update ar

        int n;
        cin >> n;
        ll a[n];
        loop(i, 0, n) cin >> a[i];
        ll x[n];
        int f = 0;
        ll mx = -inf;
        loop(i, 0, n) {
            x[i] = a[i];
            loop(j, 0, i) x[j] = min(a[j], x[j + 1]);
            rep(j, i + 1, n) x[j] = min(x[j - 1], a[j]);
            ll s = accumulate(x, x + n, 0ll);
            if(mx < s ) {
                mx = s;
                f = i;
            }
        }
        x[f] = a[f];
        loop(j, f + 1, n) x[j] = min(x[j - 1], a[j]);
        rep(j ,0, f) x[j] = min(x[j + 1], a[j]);
        prx(x, n);

}


// skyscrappers

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const ll X = 2e6;
const ll inf = 1e9 + 7ll;
#define pr(x)               printf("%lld", x)
#define in(x)               scanf("%lld", &x)
#define all(x)              x.begin(), x.end()
#define le(x)               cout << #x << ' ' << x << '\n'
#define xd                  cout << '\n'
#define fi                  first
#define se                  second
#define pb                  push_back
#define vl                  vector<ll>
#define show(x)             cout << #x << " : "; for(auto i : x) cout << i << ' '; xd
#define Google              ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define Code()              Google;  int T; cin >> T; while(T-- )
#define loop(i, a, b)       for(int i = a; i < b; ++i )
#define rep(i, a, b)        for(int i = b - 1; i >= a; --i)
#define inx(a, n)           loop(i, 0, n) cin >> a[i]
#define prx(a, n)           cout << #a << " : "; loop(i, 0, n) cout << a[i] << ' '; xd
int main()
{
        Google;
        int n;
        cin >> n;
        vl a(n), b(n);
        inx(a, n);
        loop(i, 0, n)
            b[i] = a[i];

        vector<int> fx, fy;

        fx.pb(a[0]);
        fy.pb(a[n - 1]);

        bool tx = 1;

        for(int i = 1; i < n; ++i ) {
            if(a[i] >= a[i - 1] and tx ) {
                fx.pb(a[i]);
            } else {
                tx = 0;
                if( a[i - 1] >= a[i] )
                    fx.pb(a[i]);
                else  {
                    a[i] = a[i - 1];
                    fx.pb(a[i]);
                }
            }
        }

        ll s = 0;
        s =  accumulate(all(fx), s);

        tx = 1;
        for(int i = n - 2; i >= 0; --i ) {
            if( b[i] >= b[i + 1] and tx) {
                fy.pb(b[i]);
            } else {
                tx = 0;
                if(b[i] > b[i + 1]) {
                    b[i] = b[i + 1];
                }
                fy.pb(b[i]) ;
            }
        }

        s = 0;
        ll sy = accumulate(all(fy), s);

        ll za = 0, zb = 0;
        for(auto i : fx) za += i;
        for(auto i : fy) zb += i;
        if( za >= zb){
            for(auto i : fx ) cout << i << " ";
        } else {
            reverse(all(fy));
            for(auto i : fy ) cout << i << " ";
        }
}


// never underestimate the laziness and freetime

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const ll X = 2e6;
const ll inf = 1e9 + 7ll;
#define pr(x)               printf("%lld", x)
#define in(x)               scanf("%lld", &x)
#define all(x)              x.begin(), x.end()
#define le(x)               cout << #x << ' ' << x << '\n'
#define xd                  cout << '\n'
#define fi                  first
#define se                  second
#define pb                  push_back
#define vi                  vector<ll>
#define show(x)             cout << #x << " : "; for(auto i : x) cout << i << ' '; xd
#define Google              ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define Code()              Google;  int T; cin >> T; while(T-- )
#define loop(i, a, b)       for(int i = a; i < b; ++i )
#define rep(i, a, b)        for(int i = b - 1; i >= a; --i)
#define inx(a, n)           loop(i, 0, n) cin >> a[i]
#define prx(a, n)           loop(i, 0, n) cout << a[i] << ' ';
int main()
{
        Google;
        // logic :: go for i'th element , update a/c for that on both sides
        // get such max a at index I , print that I update ar
        int n;
        cin >> n;
        ll a[n];
        loop(i, 0, n) cin >> a[i];
        ll x[n];
        int f = 0;
        ll mx = -inf;
        loop(i, 0, n) {
            x[i] = a[i];
            loop(j, 0, i) x[j] = min(x[j], x[j + 1]);
            rep(j, i + 1, n) x[j] = min(x[j - 1], a[j]);
            ll s = accumulate(x, x + n, 0ll);
            if(mx < s ) {
                mx = s;
                f = i;
            }
        }
        x[f] = a[f];
        loop(j, f + 1, n) x[j] = min(x[j - 1], a[j]);
        rep(j ,0, f) x[j] = min(x[j + 1], a[j]);
        prx(x, n);

}


#include<bits/stdc++.h>
using namespace std ;
typedef long long int ll ;
int main() {
    int n ;
    cin>> n ;
    ll a[n] ;
    for(int i=0;i<n;++i )
        cin>>a[i] ;

    ll dp[4][n];
    for(int i=0;i<4;++i )
        for(int j=0;j<n;++j )
            dp[i][j] = 0ll ;
    // inc_dec or inc forw 1
    if(a[1] > a[0] ) {
        dp[0][0] = a[0] ;
        bool f=1 ;
        for(int i=1;i<n;++i ) {
            if( f && a[i] > a[i-1] ) {
                dp[0][i] = a[i] ;
                continue ;
            }
            dp[0][i] = min(dp[0][i-1], a[i]  ) ;
            f= 0 ;
        }
    }
    // inc_dec or inc backw 1

    // dec_for 3
    if(a[0] > a[1] ) {
        dp[3][0] = a[0] ;
        for(int i=1;i<n; ++i ) {
            dp[3][i] = min(dp[3][i-1] , a[i] ) ;
        }
    }
    // dec_back 2

    ll f[4]={0ll} , k_=0ll  ;
    for(int i=0;i<4;++i )
        for(int j=0;j<n;++j )
            f[i] += dp[i][j] ;
    int k= -1 ;
    for(int i=0;i<4;++i )
        if(f[i]> k_ )
            k_= f[i] ,k = i ;

    for(int i=0;i<n;++i ) cout<<dp[k][i] <<" " ;
}


// never underestimate the laziness and freetime

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const ll X = 2e6;
const ll inf = 1e9 + 7ll;
#define pr(x)               printf("%lld", x)
#define in(x)               scanf("%lld", &x)
#define all(x)              x.begin(), x.end()
#define le(x)               cout << #x << ' ' << x << '\n'
#define xd                  cout << '\n'
#define fi                  first
#define se                  second
#define pb                  push_back
#define vi                  vector<ll>
#define show(x)             cout << #x << " : "; for(auto i : x) cout << i << ' '; xd
#define Google              ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define Code()              Google;  int T; cin >> T; while(T-- )
#define loop(i, a, b)       for(int i = a; i < b; ++i )
#define rep(i, b, a)        for(int i = b - 1; i >= a; --i)
#define inx(a, n)           loop(i, 0, n) cin >> a[i]
#define prx(a, n)           loop(i, 0, n) cout << a[i] << ' ';
int main()
{
        Google;
        // logic :: go for i'th element , update a/c for that on both sides
        // get such max a at index I , print that I update ar
        int n;
        cin >> n;
        ll a[n];
        loop(i, 0, n) cin >> a[i];
        ll x[n];
        int f = 0;
        ll mx = 0;
        loop(i, 0, n) {
            x[i] = a[i];
            loop(j, i + 1, n)
                x[j] = min( x[j - 1], a[j] );
            rep(j, i, 0)
                x[j] = min( a[j], x[j + 1] );

            ll s = accumulate(x, x + n, 0ll);
            if(mx < s) {
                mx = s;
                f = i;
            }
        }

        x[f] = a[f];
        loop(j, f + 1, n)
            x[j] = min(x[j - 1], a[j]);
        rep(j , f, 0)
            x[j] = min(x[j + 1], a[j] );

        prx(x, n);

}


// skyscrappers

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const ll X = 2e6;
const ll inf = 1e9 + 7ll;
#define pr(x)               printf("%lld", x)
#define in(x)               scanf("%lld", &x)
#define all(x)              x.begin(), x.end()
#define le(x)               cout << #x << ' ' << x << '\n'
#define xd                  cout << '\n'
#define fi                  first
#define se                  second
#define pb                  push_back
#define vl                  vector<ll>
#define show(x)             cout << #x << " : "; for(auto i : x) cout << i << ' '; xd
#define Google              ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define Code()              Google;  int T; cin >> T; while(T-- )
#define loop(i, a, b)       for(int i = a; i < b; ++i )
#define rep(i, a, b)        for(int i = b - 1; i >= a; --i)
#define inx(a, n)           loop(i, 0, n) cin >> a[i]
#define prx(a, n)           cout << #a << " : "; loop(i, 0, n) cout << a[i] << ' '; xd
int main()
{
        Google;
        int n;
        cin >> n;
        vl a(n), b(n);
        inx(a, n);
        loop(i, 0, n)
            b[i] = a[i];

        vector<int> fx, fy;

        fx.pb(a[0]);
        fy.pb(a[n - 1]);

        bool tx = 1;

        for(int i = 1; i < n; ++i ) {
            if(a[i] >= a[i - 1] and tx ) {
                fx.pb(a[i]);
            } else {
                tx = 0;
                if( a[i - 1] > a[i] )
                    fx.pb(a[i]);
                else  {
                    a[i] = a[i - 1];
                    fx.pb(a[i]);
                }
            }
        }

        ll s = 0;
        s =  accumulate(all(fx), s);

        tx = 1;
        for(int i = n - 2; i >= 0; --i ) {
            if( b[i] >= b[i + 1] and tx) {
                fy.pb(b[i]);
            } else {
                tx = 0;
                if(b[i] > b[i + 1]) {
                    b[i] = b[i + 1];
                }
                fy.pb(b[i]) ;
            }
        }

        s = 0;
        ll sy = accumulate(all(fy), s);
        if( sy <= s ) {
            for(auto i : fy )
                cout << i << " ";
            cout << endl;
        } else {
             for(auto i : fx )
                cout << i << " ";
            cout << endl;
        }

}


#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e3+10;
int a[MAXN];
int n;
long long search(int p){
    long long sum = 0;
    int now = a[p];
    for(int i = p+1 ; i < n ; i++){
        if(a[i] > now) sum += now;
        else{
            now = a[i];
            sum += now;
        }
    }
    now = a[p];
    for(int i = p ; i >= 0 ; i--){
        if(a[i] > now) sum += now;
        else{
            now = a[i];
            sum += now;
        }
    }
    return sum;
}
int main(){
    int p = 0;
    ios::sync_with_stdio(0);
    long long sum = 0;
    cin >> n;
    for(int i = 0 ; i < n ; i++){
        cin >> a[i];
    }
    for(int i = 0 ; i < n ; i++){
        long long temp = search(i);
        if(sum < temp){
            sum = temp;
            p = i;
        }
    }
    int now = a[p];
    for(int i = p+1 ; i < n ; i++){
        if(a[i] > now) a[i] = now;
        else now = a[i];
    }
    now = a[p];
    for(int i = p-1 ; i >= 0 ; i--){
        if(a[i] > now) a[i] = now;
        else now = a[i];
    }
    for(int i = 0 ; i < n ; i++){
        cout << a[i] << " ";
    }
}


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

int mkPeak(ll *arr, int left, int right, int peakPos)
{
    ll prev = arr[peakPos];
    ll sum =arr[peakPos];
    for(int i=peakPos+1; i<=right; i++)
    {
        if(arr[i]>prev) arr[i] = prev;
        else prev = arr[i];
        sum+= prev;
    }
    prev = arr[peakPos];
    for(int i=peakPos-1; i>=left; i--)
    {
        if(arr[i]>prev) arr[i] = prev;
        else prev = arr[i];
        sum+= prev;
        // cout<<"prev: "<<prev<<endl;
    }
    return sum;
}
void updateArr(ll arr[], int left, int right, int peakPos)
{
    ll prev = arr[peakPos];
    for(int i=peakPos+1; i<=right; i++)
    {
        if(arr[i]>prev) arr[i] = prev;
        else prev = arr[i];
    }
    prev = arr[peakPos];
    for(int i=peakPos-1; i>=left; i--)
    {
        if(arr[i]>prev) arr[i] = prev;
        else prev = arr[i];
    }
}

void display(ll arr[], int s)
{
    for(int i=0; i<s; i++)
    {
        cout<<arr[i]<<" ";
    }
    cout<<endl;
}
int main()
{
    int n; cin>>n;
    ll m[n];
    for(int i=0; i<n; i++) cin>>m[i];
    // display(m, n);
    ll maxSum=0;
    int peakPosition = 0;
    for(int i=0; i<n; i++)
    {
        ll temp[n]; //temp array to check a case
        for(int i=0; i<n; i++) temp[i] = m[i];
        ll sum = mkPeak(temp, 0, n-1, i);
        if(sum>maxSum)
        {
            maxSum = sum;
            peakPosition = i;
        }
    }

    updateArr(m, 0, n-1, peakPosition);
    display(m, n);
    return 0;
}


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

int mkPeak(ll *arr, int left, int right, int peakPos)
{
    ll prev = arr[peakPos];
    ll sum =arr[peakPos];
    for(int i=peakPos+1; i<=right; i++)
    {
        if(arr[i]>prev) arr[i] = prev;
        else prev = arr[i];
        sum+= prev;
    }
    prev = arr[peakPos];
    for(int i=peakPos-1; i>=left; i--)
    {
        if(arr[i]>prev) arr[i] = prev;
        else prev = arr[i];
        sum+= prev;
        // cout<<"prev: "<<prev<<endl;
    }
    return sum;
}
void updateArr(ll arr[], int left, int right, int peakPos)
{
    ll prev = arr[peakPos];
    for(int i=peakPos+1; i<=right; i++)
    {
        if(arr[i]>prev) arr[i] = prev;
        else prev = arr[i];
    }
    prev = arr[peakPos];
    for(int i=peakPos-1; i>=left; i--)
    {
        if(arr[i]>prev) arr[i] = prev;
        else prev = arr[i];
    }
}

void display(ll arr[], int s)
{
    for(int i=0; i<s; i++)
    {
        cout<<arr[i]<<" ";
    }
    cout<<endl;
}
int main()
{
    int n; cin>>n;
    ll m[n];
    for(int i=0; i<n; i++) cin>>m[i];
    display(m, n);
    ll maxSum=0;
    int peakPosition = 0;
    for(int i=0; i<n; i++)
    {
        ll temp[n]; //temp array to check a case
        for(int i=0; i<n; i++) temp[i] = m[i];
        ll sum = mkPeak(temp, 0, n-1, i);
        if(sum>maxSum)
        {
            maxSum = sum;
            peakPosition = i;
        }
    }
    updateArr(m, 0, n-1, peakPosition);
    display(m, n);
    return 0;
}


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

int mkPeak(ll *arr, int left, int right, int peakPos)
{
    ll prev = arr[peakPos];
    ll sum =arr[peakPos];
    for(int i=peakPos+1; i<=right; i++)
    {
        if(arr[i]< prev) prev = arr[i];
        sum+= prev;
    }
    prev = arr[peakPos];
    for(int i=peakPos-1; i>=left; i--)
    {
        if(arr[i] < prev) prev = arr[i];
        sum+= prev;
        // cout<<"prev: "<<prev<<endl;
    }
    return sum;
}
void updateArr(ll arr[], int left, int right, int peakPos)
{
    ll prev = arr[peakPos];
    for(int i=peakPos+1; i<=right; i++)
    {
        if(arr[i]>prev) arr[i] = prev;
        else prev = arr[i];
    }
    prev = arr[peakPos];
    for(int i=peakPos-1; i>=left; i--)
    {
        if(arr[i]>prev) arr[i] = prev;
        else prev = arr[i];
    }
}

void display(ll arr[], int s)
{
    for(int i=0; i<s; i++)
    {
        cout<<arr[i]<<" ";
    }
    // cout<<endl;
}
int main()
{
    ios::sync_with_stdio(0);
    int n; cin>>n;
    ll m[n];
    for(int i=0; i<n; i++) cin>>m[i];
    // display(m, n);
    ll maxSum=0;
    int peakPosition = 0;
    for(int i=0; i<n; i++)
    {
        ll sum = mkPeak(m, 0, n-1, i);
        if(sum>maxSum)
        {
            maxSum = sum;
            peakPosition = i;
        }
    }

    updateArr(m, 0, n-1, peakPosition);
    display(m, n);
    return 0;
}


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

ll mkPeak(ll *arr, int left, int right, int peakPos)
{
    ll prev = arr[peakPos];
    ll sum =arr[peakPos];
    for(int i=peakPos+1; i<=right; i++)
    {
        if(arr[i]< prev) prev = arr[i];
        sum+= prev;
    }
    prev = arr[peakPos];
    for(int i=peakPos-1; i>=left; i--)
    {
        if(arr[i] < prev) prev = arr[i];
        sum+= prev;
        // cout<<"prev: "<<prev<<endl;
    }
    return sum;
}
void updateArr(ll arr[], int left, int right, int peakPos)
{
    ll prev = arr[peakPos];
    for(int i=peakPos+1; i<=right; i++)
    {
        if(arr[i]>prev) arr[i] = prev;
        else prev = arr[i];
    }
    prev = arr[peakPos];
    for(int i=peakPos-1; i>=left; i--)
    {
        if(arr[i]>prev) arr[i] = prev;
        else prev = arr[i];
    }
}

void display(ll arr[], int s)
{
    for(int i=0; i<s; i++)
    {
        cout<<arr[i]<<" ";
    }
    // cout<<endl;
}
int main()
{
    ios::sync_with_stdio(0);
    int n; cin>>n;
    ll m[n];
    for(int i=0; i<n; i++) cin>>m[i];
    // display(m, n);
    ll maxSum=0;
    int peakPosition = 0;
    for(int i=0; i<n; i++)
    {
        ll sum = mkPeak(m, 0, n-1, i);
        if(sum>maxSum)
        {
            maxSum = sum;
            peakPosition = i;
        }
    }

    updateArr(m, 0, n-1, peakPosition);
    display(m, n);
    return 0;
}