#include <bits/stdc++.h>
using namespace std;
#define pb push_back
int ucitaj()
{
	int rez=0;
	char ch;
	while(true)
	{
		ch=getchar();
		if (ch<'0' or ch>'9') break;
		rez=rez*10+(ch-'0');
	}
	return rez;
}
int main()
{
	int n,i,a,b,max1,max2,km1,km2;
	vector <int> A;
	n=ucitaj();
	if (n==2)
	{
		max1=ucitaj();
		max2=ucitaj();
		printf("%d ",max2);
		printf("%d",max1);
	}
	else
	{
		max1=ucitaj();
		max2=ucitaj();
		A.pb(max1);
		A.pb(max2);
		km1=0;
		km2=1;
		for (i=0;i<n-2;i++)
		{
			A.pb(ucitaj());
		}
		if (max2>max1)
		{
			b=max1;
			max1=max2;
			max2=b;
			km1=1;
			km2=0;
		}
		for (i=2;i<=n-1;i++)
		{
			if (A[i]>max1)
			{
				b=max1;
				max1=A[i];
				max2=b;
				a=km1;
				km1=i;
				km2=a;
			}
			else
			{
				if (A[i]>max2)
				{
					max2=A[i];
					km2=i;
				}
			}
		}
		b=A[0];
		A[0]=A[km1];
		A[km1]=b;
		b=A[1];
		A[1]=A[km2];
		A[km2]=b;
		for (i=0;i<n;i++)
		{
			printf("%d ",A[i]);
		}
	}
}