#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
using namespace std;
unsigned long long int main()
{
    unsigned long long int n;
    unsigned long long int *a=(unsigned long long int*)malloc(n*sizeof(unsigned long long int));
    scanf("%ulld",&n);
    for(unsigned long long int i=0;i<n;i++)
    {
        unsigned long long int x;
        scanf("%ulld",&x);
        a[i]=x;
    }
    
    unsigned long long int i;
    
    for(i=0;i<n;i++)
    {
        unsigned long long int* k=max_element(a+i+1,a+n);
        if(a[i]<*k)
        {
            unsigned long long int t=a[i];
            a[i]=*k;
            *k=t;
            i=n+1;
        }
    }
    if(i==n)
    {
        unsigned long long int t=a[n-1];
        a[n-1]=a[n-2];
        a[n-2]=t;
    }
    
    for(unsigned long long int i=0;i<n;i++)
        printf("%ulld ",a[i]);
    return 0;
}