package com.company;
import java.util.Scanner;

public class Main {
    public static void main(String[] args)
    {
        Scanner input = new Scanner(System.in);
        int n = input.nextInt();
        int[] niz1=new int[n];
        int[] niz2=new int[n];
        for(int i=0;i<n;i++)
        {
            niz1[i]=input.nextInt();
            niz2[i]=niz1[i];
        }
        if(n==1)
        {
            System.out.print(niz1[0]);
        }
        else if(n==2)
        {
            System.out.print(niz1[1] + " " + niz1[0]);
        }
        else
        {
            int i1 = 0;
            int ops = 0;
            for (int k = 0; k < n; k++)
            {
                if (niz1[k] > ops )
                {
                    ops = niz1[k];
                }
            }
            int[] br=new int[ops + 1];
            int[] aut=new int[n];
            for (int k = 0; k < ops + 1; k++)
            {
                br[k]=0;
            }
            for(int i = 0; i < n; i++)
            {
                br[niz1[i]] = br[niz1[i]] + 1;
            }
            for (int i = 1; i <= ops; i++)
            {
                br[i] = br[i] + br[i-1];
            }
            for (int i = 0; i < n; i++)
            {
                aut[br[niz1[i]]-1] = niz1[i];
                br[niz1[i]] = br[niz1[i]] - 1;
            }
            for (int i = 0; i < n; i++)
            {
                niz1[i] = aut[i];
            }
            for (int i = 0; i < niz1.length / 2; i++) {
                int temp = niz1[i];
                niz1[i] = niz1[niz1.length - 1 - i];
                niz1[niz1.length - 1 - i] = temp;
            }
            int i3=0;
            int i4 = 0;
            boolean b=true;
            while(b)
            {
                if(niz1[i3]!=niz2[i3])
                {
                    i4=1 + i3;
                    i1=i3;
                    b=false;
                }
                i3++;
            }
            int max=Integer.MIN_VALUE;
            int i2 = 0;
            for(int i=i4;i<n;i++)
            {
                if(niz2[i]>max)
                {
                    max=niz2[i];
                    i2=i;
                }
            }
            int pom=niz2[i1];
            niz2[i1]=niz2[i2];
            niz2[i2]=pom;
            for(int i=0;i<n;i++) {
                System.out.print(niz2[i]);
                System.out.print(" ");
            }
        }
    }
    }