#include<iostream>

using namespace std;

int main() {
	int N, max, xj, t, placeholder;
	cin>>N;
	int x[N];
	for (int i = 0; i < N; i++){
		cin>>x[i];
	}
	if (N < 3){
		if (N == 1){
			cout<<x[0];
		}
		else{
			cout<<x[1]<<" "<<x[0];
		}
	}
	else{
		for (int j = 0; j < N-1; j++){
			max = x[j];
			xj = x[j];
			for (int p = j+1; p<N; p++){
				if (x[p] > max){
					max = x[p];
					t = p;			
				}				
			}
			if (xj != max){
				x[t] = x[j];
				x[j] = max;				
				for (int q = 0; q < N; q++){
					cout<<x[q]<<" ";
				}
				return 0;			
			}
		}
		placeholder = x[N-2];
		x[N-2] = x[N-1];
		x[N-1] = placeholder;
		for (int r = 0; r < N; r++){
			cout<<x[r]<<" ";
		}
	}
	return 0;
}