import java.util.*;

public class Main{
    public static void main(String[] args){
    //入力
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        Integer[] A = new Integer[N];
        Integer[] B = new Integer[N];
        for(int i=0;i<N;i++){
            A[i] = sc.nextInt();
            B[i] = A[i];
        }
        Arrays.sort(A, Comparator.reverseOrder());
        int max = A[0];
        int second = A[1];

    //処理
        for (int i=0;i<N;i++){
            System.out.println((B[i]==max)?second:max);
        }
        sc.close();

    }
} import java.util.*; util.* java public class Main{
    public static void main(String[] args){
    //入力
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        Integer[] A = new Integer[N];
        Integer[] B = new Integer[N];
        for(int i=0;i<N;i++){
            A[i] = sc.nextInt();
            B[i] = A[i];
        }
        Arrays.sort(A, Comparator.reverseOrder());
        int max = A[0];
        int second = A[1];

    //処理
        for (int i=0;i<N;i++){
            System.out.println((B[i]==max)?second:max);
        }
        sc.close();

    }
} Main public static void main(String[] args){
    //入力
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        Integer[] A = new Integer[N];
        Integer[] B = new Integer[N];
        for(int i=0;i<N;i++){
            A[i] = sc.nextInt();
            B[i] = A[i];
        }
        Arrays.sort(A, Comparator.reverseOrder());
        int max = A[0];
        int second = A[1];

    //処理
        for (int i=0;i<N;i++){
            System.out.println((B[i]==max)?second:max);
        }
        sc.close();

    } main {
    //入力
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        Integer[] A = new Integer[N];
        Integer[] B = new Integer[N];
        for(int i=0;i<N;i++){
            A[i] = sc.nextInt();
            B[i] = A[i];
        }
        Arrays.sort(A, Comparator.reverseOrder());
        int max = A[0];
        int second = A[1];

    //処理
        for (int i=0;i<N;i++){
            System.out.println((B[i]==max)?second:max);
        }
        sc.close();

    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int N = sc.nextInt(); N sc.nextInt() sc.nextInt sc Integer[] A = new Integer[N]; A new Integer[N] N Integer[] B = new Integer[N]; B new Integer[N] N for(int i=0;i<N;i++){
            A[i] = sc.nextInt();
            B[i] = A[i];
        } int i=0; int i=0; i 0 i<N i N i++ i++ i {
            A[i] = sc.nextInt();
            B[i] = A[i];
        } {
            A[i] = sc.nextInt();
            B[i] = A[i];
        } A[i] = sc.nextInt() A[i] A i sc.nextInt() sc.nextInt sc B[i] = A[i] B[i] B i A[i] A i Arrays.sort(A, Comparator.reverseOrder()) Arrays.sort Arrays A Comparator.reverseOrder() Comparator.reverseOrder Comparator int max = A[0]; max A[0] A 0 int second = A[1]; second A[1] A 1 for (int i=0;i<N;i++){
            System.out.println((B[i]==max)?second:max);
        } int i=0; int i=0; i 0 i<N i N i++ i++ i {
            System.out.println((B[i]==max)?second:max);
        } {
            System.out.println((B[i]==max)?second:max);
        } System.out.println((B[i]==max)?second:max) System.out.println System.out System System.out (B[i]==max)?second:max (B[i]==max) B[i] B i max second max sc.close() sc.close sc String[] args args public class Main{
    public static void main(String[] args){
    //入力
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        Integer[] A = new Integer[N];
        Integer[] B = new Integer[N];
        for(int i=0;i<N;i++){
            A[i] = sc.nextInt();
            B[i] = A[i];
        }
        Arrays.sort(A, Comparator.reverseOrder());
        int max = A[0];
        int second = A[1];

    //処理
        for (int i=0;i<N;i++){
            System.out.println((B[i]==max)?second:max);
        }
        sc.close();

    }
} public class Main{
    public static void main(String[] args){
    //入力
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        Integer[] A = new Integer[N];
        Integer[] B = new Integer[N];
        for(int i=0;i<N;i++){
            A[i] = sc.nextInt();
            B[i] = A[i];
        }
        Arrays.sort(A, Comparator.reverseOrder());
        int max = A[0];
        int second = A[1];

    //処理
        for (int i=0;i<N;i++){
            System.out.println((B[i]==max)?second:max);
        }
        sc.close();

    }
} Main
import java.util.*;

public class Main{
    public static void main(String[] args){
    //入力
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        Integer[] A = new Integer[N];
        Integer[] B = new Integer[N];
        for(int i=0;i<N;i++){
            A[i] = sc.nextInt();
            B[i] = A[i];
        }
        Arrays.sort(A, Comparator.reverseOrder());
        int max = A[0];
        int second = A[1];

    //処理
        for (int i=0;i<N;i++){
            System.out.println((B[i]==max)?second:max);
        }
        sc.close();

    }
}
