#include<stdio.h>

int main()
{
	int a[1000000], n, s = 0;
	scanf("%d", &n);
	for(int i = 0; i < n; i++) scanf("%d", &a[i]);
	for(int i = 0; !s && i < n; i++)
	{
		int max = -1, maxi = i;
		for(int j = i + 1; j < n; j++)
			if(a[i] >= max)
			{
				max = a[j];
				maxi = j;
			}
		if(max > a[i])
		{
			int h = a[i];
			a[i] = a[maxi];
			a[maxi] = h;
			s = 1;
		}
	}
	if(!s)
	{
		int h = a[n - 2];
		a[n - 2] = a[n - 1];
		a[n - 1] = h;
	}
	for(int i = 0; i < n; i++) printf("%d ", a[i]);
}