#include <iostream>
using namespace std;
int main()
{
int n, a[100];
cin >> n;
for(int i = 0; i < n; i++)
cin >> a[i];
int max = 0;
for(int i = 0; i < n; i++)
if(a[i] > max)
max = a[i];
int min = 99999;
for(int i = 0; i < n; i++)
if(a[i] < min)
min = a[i];
for(int i = 0; i < n; i++)
if(a[i] == max)
a[i] == min;
for(int i = 0; i < n; i++)
if(a[i] == min)
a[i] == max;
for(int i = 0; i < n; i++)
cout << a[i] << " ";
return 0;
}