#include <bits/stdc++.h>
using namespace std;
int main ()
{
	freopen ("RN.inp","r",stdin);
	freopen ("RN.out","w",stdout);
	int b=0,c,x,d,e,f,n,max=0, min=1000000000; cin>>n;
	long  a[2*n+2];
	for (int i=1; i<=n; i++)
	cin>> a[i];
	 
	for (int y=n+1; y<=2*n; y++)
	a[y]=a[y-n];
	for ( x=1; x<2*n; x++)
	{
		
		if (a[x]<a[x+1])
		{
			b=0;
			d=0; 
			f=x;
		while (a[f]<a[f+1])
		{
			b++;
			d+=a[f];
			f++;
		}
		b++;
		d+=a[f];
		if (b>max||(b==max&&d<min)) 
			{
				max=b;
				min=d;
				c=x;
			}
	}
}
	for (e=c; e<c+max; e++)
	cout << a[e]<<" ";
}
