import java.util.*;
public class Main{
    public static void main(String[] aargs){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        Integer[] A = new Integer[N];
        for(int i=0;i<N;i++){
            A[i] = sc.nextInt();
        }
        Integer B[] = A.clone();
        Arrays.sort(A,Collections.reverseOrder());
        for(int i=0;i<N;i++){
            if(B[i]!=A[0]){
                System.out.println(A[0]);
            }
            else{
                System.out.println(A[1]);
            }
        }
    }
} import java.util.*; util.* java public class Main{
    public static void main(String[] aargs){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        Integer[] A = new Integer[N];
        for(int i=0;i<N;i++){
            A[i] = sc.nextInt();
        }
        Integer B[] = A.clone();
        Arrays.sort(A,Collections.reverseOrder());
        for(int i=0;i<N;i++){
            if(B[i]!=A[0]){
                System.out.println(A[0]);
            }
            else{
                System.out.println(A[1]);
            }
        }
    }
} Main public static void main(String[] aargs){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        Integer[] A = new Integer[N];
        for(int i=0;i<N;i++){
            A[i] = sc.nextInt();
        }
        Integer B[] = A.clone();
        Arrays.sort(A,Collections.reverseOrder());
        for(int i=0;i<N;i++){
            if(B[i]!=A[0]){
                System.out.println(A[0]);
            }
            else{
                System.out.println(A[1]);
            }
        }
    } main {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        Integer[] A = new Integer[N];
        for(int i=0;i<N;i++){
            A[i] = sc.nextInt();
        }
        Integer B[] = A.clone();
        Arrays.sort(A,Collections.reverseOrder());
        for(int i=0;i<N;i++){
            if(B[i]!=A[0]){
                System.out.println(A[0]);
            }
            else{
                System.out.println(A[1]);
            }
        }
    } 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 for(int i=0;i<N;i++){
            A[i] = sc.nextInt();
        } int i=0; int i=0; i 0 i<N i N i++ i++ i {
            A[i] = sc.nextInt();
        } {
            A[i] = sc.nextInt();
        } A[i] = sc.nextInt() A[i] A i sc.nextInt() sc.nextInt sc Integer B[] = A.clone(); B A.clone() A.clone A Arrays.sort(A,Collections.reverseOrder()) Arrays.sort Arrays A Collections.reverseOrder() Collections.reverseOrder Collections for(int i=0;i<N;i++){
            if(B[i]!=A[0]){
                System.out.println(A[0]);
            }
            else{
                System.out.println(A[1]);
            }
        } int i=0; int i=0; i 0 i<N i N i++ i++ i {
            if(B[i]!=A[0]){
                System.out.println(A[0]);
            }
            else{
                System.out.println(A[1]);
            }
        } {
            if(B[i]!=A[0]){
                System.out.println(A[0]);
            }
            else{
                System.out.println(A[1]);
            }
        } if(B[i]!=A[0]){
                System.out.println(A[0]);
            }
            else{
                System.out.println(A[1]);
            } B[i]!=A[0] B[i] B i A[0] A 0 {
                System.out.println(A[0]);
            } System.out.println(A[0]) System.out.println System.out System System.out A[0] A 0 {
                System.out.println(A[1]);
            } System.out.println(A[1]) System.out.println System.out System System.out A[1] A 1 String[] aargs aargs public class Main{
    public static void main(String[] aargs){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        Integer[] A = new Integer[N];
        for(int i=0;i<N;i++){
            A[i] = sc.nextInt();
        }
        Integer B[] = A.clone();
        Arrays.sort(A,Collections.reverseOrder());
        for(int i=0;i<N;i++){
            if(B[i]!=A[0]){
                System.out.println(A[0]);
            }
            else{
                System.out.println(A[1]);
            }
        }
    }
} public class Main{
    public static void main(String[] aargs){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        Integer[] A = new Integer[N];
        for(int i=0;i<N;i++){
            A[i] = sc.nextInt();
        }
        Integer B[] = A.clone();
        Arrays.sort(A,Collections.reverseOrder());
        for(int i=0;i<N;i++){
            if(B[i]!=A[0]){
                System.out.println(A[0]);
            }
            else{
                System.out.println(A[1]);
            }
        }
    }
} Main
import java.util.*;
public class Main{
    public static void main(String[] aargs){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        Integer[] A = new Integer[N];
        for(int i=0;i<N;i++){
            A[i] = sc.nextInt();
        }
        Integer B[] = A.clone();
        Arrays.sort(A,Collections.reverseOrder());
        for(int i=0;i<N;i++){
            if(B[i]!=A[0]){
                System.out.println(A[0]);
            }
            else{
                System.out.println(A[1]);
            }
        }
    }
}