#include <iostream>
using namespace std;

void replace(int arr[], int start,int n) {
	int max = arr[start], x;
	if (start == n) { int a = arr[1]; arr[1] = arr[2]; arr[2] = a; }
	for (int i = start; i < n; i++) {
		if (arr[i] > max) {
			max = arr[i]; x = i;
		}
	}
	if (arr[0] == max)replace(arr, start + 1,n);
	else
	{
		arr[x] = arr[start]; arr[start] = max;
	}
}

int main()
{
	int n, * arr;
	cin >> n; arr = new int[n];
	for (int i = 0; i < n; cin >> arr[i], i++);
	if (n == 2) { int a = arr[0]; arr[0] = arr[1]; arr[1] = a; }
	else
	{
		replace(arr, 0,n);
	}
	for (int i = 0; i < n; cout << arr[i] << ' ', i++);
	return 0;
}