#include<iostream>
#include<vector>
#include <algorithm>
using namespace std;
int main()
{
int n;
cin>>n;
vector <int> v(n);
for (int i=0;i<n;i++)
{
cin>>v[i];
}
auto max = max_element(v.begin(), v.end());
auto min = min_element(v.begin(), v.end());
int mmin=min-v.begin();
int mmax=max-v.begin();
int a1=v[0],a2=v[mmin],a3=v[n-1],a4=v[mmax];
v[0]=a2,v[mmin]=a1,v[n-1]=a4,v[mmax]=a3;
for (int i=0;i<n;i++)
{cout<<v[i]<<" ";
}
r