import java.util.*;

public class Main {

    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);

        int N = scanner.nextInt();
        int[] A = new int[N];
        int[] B = new int[N];

        for(int i=0; i<N; i++){
            int tmp = scanner.nextInt();
            A[i] = tmp;
            B[i] = tmp;
        }

        Arrays.sort(A);

        int first = A[N-1];
        int second = A[N-2];

        for(int i=0; i<N; i++){
            if(B[i] == first){
                System.out.println(second);
            }else{
                System.out.println(first);
            }
        }
    }
} import java.util.*; util.* java public class Main {

    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);

        int N = scanner.nextInt();
        int[] A = new int[N];
        int[] B = new int[N];

        for(int i=0; i<N; i++){
            int tmp = scanner.nextInt();
            A[i] = tmp;
            B[i] = tmp;
        }

        Arrays.sort(A);

        int first = A[N-1];
        int second = A[N-2];

        for(int i=0; i<N; i++){
            if(B[i] == first){
                System.out.println(second);
            }else{
                System.out.println(first);
            }
        }
    }
} Main public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);

        int N = scanner.nextInt();
        int[] A = new int[N];
        int[] B = new int[N];

        for(int i=0; i<N; i++){
            int tmp = scanner.nextInt();
            A[i] = tmp;
            B[i] = tmp;
        }

        Arrays.sort(A);

        int first = A[N-1];
        int second = A[N-2];

        for(int i=0; i<N; i++){
            if(B[i] == first){
                System.out.println(second);
            }else{
                System.out.println(first);
            }
        }
    } main {

        Scanner scanner = new Scanner(System.in);

        int N = scanner.nextInt();
        int[] A = new int[N];
        int[] B = new int[N];

        for(int i=0; i<N; i++){
            int tmp = scanner.nextInt();
            A[i] = tmp;
            B[i] = tmp;
        }

        Arrays.sort(A);

        int first = A[N-1];
        int second = A[N-2];

        for(int i=0; i<N; i++){
            if(B[i] == first){
                System.out.println(second);
            }else{
                System.out.println(first);
            }
        }
    } Scanner scanner = new Scanner(System.in); scanner new Scanner(System.in) int N = scanner.nextInt(); N scanner.nextInt() scanner.nextInt scanner int[] A = new int[N]; A new int[N] N int[] B = new int[N]; B new int[N] N for(int i=0; i<N; i++){
            int tmp = scanner.nextInt();
            A[i] = tmp;
            B[i] = tmp;
        } int i=0; int i=0; i 0 i<N i N i++ i++ i {
            int tmp = scanner.nextInt();
            A[i] = tmp;
            B[i] = tmp;
        } {
            int tmp = scanner.nextInt();
            A[i] = tmp;
            B[i] = tmp;
        } int tmp = scanner.nextInt(); tmp scanner.nextInt() scanner.nextInt scanner A[i] = tmp A[i] A i tmp B[i] = tmp B[i] B i tmp Arrays.sort(A) Arrays.sort Arrays A int first = A[N-1]; first A[N-1] A N-1 N 1 int second = A[N-2]; second A[N-2] A N-2 N 2 for(int i=0; i<N; i++){
            if(B[i] == first){
                System.out.println(second);
            }else{
                System.out.println(first);
            }
        } int i=0; int i=0; i 0 i<N i N i++ i++ i {
            if(B[i] == first){
                System.out.println(second);
            }else{
                System.out.println(first);
            }
        } {
            if(B[i] == first){
                System.out.println(second);
            }else{
                System.out.println(first);
            }
        } if(B[i] == first){
                System.out.println(second);
            }else{
                System.out.println(first);
            } B[i] == first B[i] B i first {
                System.out.println(second);
            } System.out.println(second) System.out.println System.out System System.out second {
                System.out.println(first);
            } System.out.println(first) System.out.println System.out System System.out first String[] args args public class Main {

    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);

        int N = scanner.nextInt();
        int[] A = new int[N];
        int[] B = new int[N];

        for(int i=0; i<N; i++){
            int tmp = scanner.nextInt();
            A[i] = tmp;
            B[i] = tmp;
        }

        Arrays.sort(A);

        int first = A[N-1];
        int second = A[N-2];

        for(int i=0; i<N; i++){
            if(B[i] == first){
                System.out.println(second);
            }else{
                System.out.println(first);
            }
        }
    }
} public class Main {

    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);

        int N = scanner.nextInt();
        int[] A = new int[N];
        int[] B = new int[N];

        for(int i=0; i<N; i++){
            int tmp = scanner.nextInt();
            A[i] = tmp;
            B[i] = tmp;
        }

        Arrays.sort(A);

        int first = A[N-1];
        int second = A[N-2];

        for(int i=0; i<N; i++){
            if(B[i] == first){
                System.out.println(second);
            }else{
                System.out.println(first);
            }
        }
    }
} Main
import java.util.*;

public class Main {

    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);

        int N = scanner.nextInt();
        int[] A = new int[N];
        int[] B = new int[N];

        for(int i=0; i<N; i++){
            int tmp = scanner.nextInt();
            A[i] = tmp;
            B[i] = tmp;
        }

        Arrays.sort(A);

        int first = A[N-1];
        int second = A[N-2];

        for(int i=0; i<N; i++){
            if(B[i] == first){
                System.out.println(second);
            }else{
                System.out.println(first);
            }
        }
    }
}
