package polica;

import java.util.Scanner;

/**
 *
 * @author Ivan
 */
public class Polica {

    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        int N = input.nextInt();
        int x, max = 0, max2, trenutni2 = 0, trenutni1 = 0,nule=0;
        int[] arr;
        arr = new int[N];
        for (int i = 0; i < N; i++) {
            arr[i] = input.nextInt();
            if(arr[i]==0){
                nule++;
            }
        }
        
        if(N - nule < 2){
            System.err.println("BAREM DVE KNJIGE NE SMEJU BITI NULA");
            return;
        }
        
        if(arr[0] == 0){
            System.err.println("PRVA KNJIGA NE SME BITI NULA");
            return;
        }

        if (N == 2) {
            x = arr[0];
            arr[0] = arr[1];
            arr[1] = x;

            for (int i = 0; i < N; i++) {
                System.out.print(arr[i] + " ");
            }
            return;
        }

        for (int i = 0; i < N; i++) {
            max = arr[0];
            if (arr[i] > max) {
                max = arr[i];
                trenutni1 = i;
            }
        }

        for (int i = 0; i < N; i++) {
            max2 = arr[1];
            if (arr[i] > max2) {
                if (arr[i]!= max) {
                    max2 = arr[i];
                    trenutni2 = i;
                }

            }
        }

        if (max != arr[0]) {
            x = arr[trenutni1];
            arr[trenutni1] = arr[0];
            arr[0] = x;
        }
        
        else{
            x = arr[trenutni2];
            arr[trenutni2] = arr[1];
            arr[1] = x;
        }

        for (int i = 0; i < N; i++) {
            System.out.print(arr[i] + " ");
        }
    }

}