#include <iostream>
#include <algorithm>
#define endl '\n'
#define print(x) cout << x << endl;
#define debug(x) cout << #x << " = " << x << endl;
#define MAXN 1000000
using namespace std;

int n;
int arr1[MAXN+1], arr2[MAXN+1], cnt[10];

bool Greater(int a, int b) { return a > b; }

void solve()
{
	for (int i = 0; i < n; i++)
	{
		if (arr1[i] != arr2[i])
		{
			swap(arr1[i], *find(arr1+i, arr1 + MAXN + 1, arr2[i]));
			return;
		}
	}
	for (int i = 0; i < 10; i++)
		if (cnt[i] >= 2)
			return;
	swap(arr1[n - 1], arr1[n - 2]);
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		cin >> arr1[i];
		cnt[arr1[i]]++;
	}
	memcpy(arr2, arr1, MAXN+1);
	sort(arr2, arr2 + MAXN + 1, Greater);
	solve();

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