#include <iostream>
#include <algorithm>
using namespace std;
int max(int a[], int n, int granica) {
	int m = a[granica], maxi = granica;
	for (int i = n; i >= granica; i--) {
		if (a[i] > m) {
			m = a[i];
			maxi = i;
		}
	}
	return maxi;
}
int main() {
	long int n;
	cin >> n;
	int *a = new int[n];
	for (int i = 0; i < n; i++) cin >> a[i];
	if (n == 2) {
		swap(a[0], a[1]);
	}
	if (n > 2) {

		for (int i = 0; i < n; i++) {
			if (a[i] != a[max(a, n, i)]) {
				swap(a[i], a[max(a, n, i)]);
				break;
			}
		}
	}
	for (int i = 0; i < n; i++) cout << a[i] << ' ';
	return 0;
}