#include <fstream>
#include <vector>

using namespace std;

int main()
{
	ifstream input("RN.inp");
	ofstream output("RN.out");

	int n, max = 0, length = 0, pos;
	input >> n;
	vector <long long> a(n);
	for (int i = 0; i < n; i++)
	{
		input >> a[i];
	}
	for (int i = 0; i < n; i++)
	{
		if (i != n - 1)
		{
			int j = i;
			int k = i + 1;
			while (a[j] < a[k])
			{
				length++;
				j++;
				k++;
				if (k >= n)
				{
					k -= n;
				}
				if (j >= n)
				{
					j -= n;
				}
			}
			if (length > max)
			{
				max = length;
				pos = i;
			}
			length = 0;
		}
		else
		{
			int j = i;
			int k = 0;
			while (a[j] < a[k])
			{
				length++;
				j++;
				k++;
				if (j >= n)
				{
					j -= n;
				}
			}
			if (length > max)
			{
				max = length;
				pos = i;
			}
			length = 0;
		}
	}
	int m = pos;
	for (int i = 0; i < max + 1; i++)
	{
		output << a[m] << ' ';
		m++;
		if (m >= n)
		{
			m -= n;
		}
	}
	input.close();
	output.close();
	return 0;
}
