#include <iostream>
#include <algorithm>
using namespace std;
int max(int a[], int n, int granica) {
	int m = a[granica], mi = granica;
	for (int i = n; i >= granica; i--) {
		if (a[i] > m) {
			m = a[i];
			mi = i;
		}
	}
	return mi;
}
int main() {
	long 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]);
		cout << a[0] << ' ' << a[1] << endl;
	}
	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;
}