#include <iostream>
#include<algorithm>
using namespace std;
int compare(const void * a, const void * b)
{
	return (*(int*)b - *(int*)a);
}

int main()
{
	int n;
	static int a[1000000], b[1000000];
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i]; b[i] = a[i];
	}
	if (n == 2)cout << a[1] << " " << a[0];
	else
	{
		qsort(b, n, sizeof(int), compare);
		
		
		int promena = 0;
		for(int i = 0;i<n;i++)
			if (a[i] != b[i]) {

				for (int j = i + 1; j < n; j++)
					if (a[j] == b[i])
					{
						a[j] = a[i]; break;
					}
			a[i] = b[i];
			promena = 1;
			break;
			}

		if (promena == 1)
			for (int i = 0; i < n; i++)cout << a[i] << " ";
		else
		{
			for (int i = 0; i < n - 2; i++)cout << a[i] << " ";
			cout << a[n - 1] << " " << a[n-2];
		}
			

	}
	

}