import java.util.*;
import java.lang.*;


public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();

        int[] A = new int[N], S = new int[N];
        for(int n=0; n<N; n++){
            A[n] = sc.nextInt();
            S[n] = A[n];
        }
        Arrays.sort(S);
        
        for(int n=0; n<N; n++){
            if(A[n] == S[N-1]) System.out.println(S[N-2]);
            else System.out.println(S[N-1]);
        }
    }
} import java.util.*; util.* java import java.lang.*; lang.* java public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();

        int[] A = new int[N], S = new int[N];
        for(int n=0; n<N; n++){
            A[n] = sc.nextInt();
            S[n] = A[n];
        }
        Arrays.sort(S);
        
        for(int n=0; n<N; n++){
            if(A[n] == S[N-1]) System.out.println(S[N-2]);
            else System.out.println(S[N-1]);
        }
    }
} Main public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();

        int[] A = new int[N], S = new int[N];
        for(int n=0; n<N; n++){
            A[n] = sc.nextInt();
            S[n] = A[n];
        }
        Arrays.sort(S);
        
        for(int n=0; n<N; n++){
            if(A[n] == S[N-1]) System.out.println(S[N-2]);
            else System.out.println(S[N-1]);
        }
    } main {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();

        int[] A = new int[N], S = new int[N];
        for(int n=0; n<N; n++){
            A[n] = sc.nextInt();
            S[n] = A[n];
        }
        Arrays.sort(S);
        
        for(int n=0; n<N; n++){
            if(A[n] == S[N-1]) System.out.println(S[N-2]);
            else System.out.println(S[N-1]);
        }
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int N = sc.nextInt(); N sc.nextInt() sc.nextInt sc int[] A = new int[N] A new int[N] N S = new int[N]; S new int[N] N for(int n=0; n<N; n++){
            A[n] = sc.nextInt();
            S[n] = A[n];
        } int n=0; int n=0; n 0 n<N n N n++ n++ n {
            A[n] = sc.nextInt();
            S[n] = A[n];
        } {
            A[n] = sc.nextInt();
            S[n] = A[n];
        } A[n] = sc.nextInt() A[n] A n sc.nextInt() sc.nextInt sc S[n] = A[n] S[n] S n A[n] A n Arrays.sort(S) Arrays.sort Arrays S for(int n=0; n<N; n++){
            if(A[n] == S[N-1]) System.out.println(S[N-2]);
            else System.out.println(S[N-1]);
        } int n=0; int n=0; n 0 n<N n N n++ n++ n {
            if(A[n] == S[N-1]) System.out.println(S[N-2]);
            else System.out.println(S[N-1]);
        } {
            if(A[n] == S[N-1]) System.out.println(S[N-2]);
            else System.out.println(S[N-1]);
        } if(A[n] == S[N-1]) System.out.println(S[N-2]);
            else System.out.println(S[N-1]); A[n] == S[N-1] A[n] A n S[N-1] S N-1 N 1 System.out.println(S[N-2]) System.out.println System.out System System.out S[N-2] S N-2 N 2 System.out.println(S[N-1]) System.out.println System.out System System.out S[N-1] S N-1 N 1 String[] args args public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();

        int[] A = new int[N], S = new int[N];
        for(int n=0; n<N; n++){
            A[n] = sc.nextInt();
            S[n] = A[n];
        }
        Arrays.sort(S);
        
        for(int n=0; n<N; n++){
            if(A[n] == S[N-1]) System.out.println(S[N-2]);
            else System.out.println(S[N-1]);
        }
    }
} public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();

        int[] A = new int[N], S = new int[N];
        for(int n=0; n<N; n++){
            A[n] = sc.nextInt();
            S[n] = A[n];
        }
        Arrays.sort(S);
        
        for(int n=0; n<N; n++){
            if(A[n] == S[N-1]) System.out.println(S[N-2]);
            else System.out.println(S[N-1]);
        }
    }
} Main
import java.util.*;
import java.lang.*;


public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();

        int[] A = new int[N], S = new int[N];
        for(int n=0; n<N; n++){
            A[n] = sc.nextInt();
            S[n] = A[n];
        }
        Arrays.sort(S);
        
        for(int n=0; n<N; n++){
            if(A[n] == S[N-1]) System.out.println(S[N-2]);
            else System.out.println(S[N-1]);
        }
    }
}
