#include <iostream>

using namespace std;

int main()
{
    int n;
    int niz[100000];
    cin>>n;
    for(int i = 0; i < n; i++)
        cin>>niz[i];

    if(n == 2)
        cout<<niz[1]<<" "<<niz[0];
    else
    {
        int max, maxi, a;
        max = niz[n-1];
        maxi = n-1;
        a = n - 1;
        for(int i = 0; i < n; i++)
            if(niz[i] >= max && niz[i] != niz[0])
            {
                max = niz[i];
                maxi = i;
            }
        for(int i = 0; i < n; i++)
            if(max > niz[i])
            {
                a = i;
                break;
            }
        int pom = niz[a];
        niz[a] = niz[maxi];
        niz[maxi] = pom;
        for(int i = 0; i < n; i++)
            cout<<niz[i]<<" ";
    }
    return 0;
}