    import java.io.FileNotFoundException;
    import java.util.Arrays;
    import java.util.Scanner;
     
    public class Main {
    	public static void main(String[] args) throws FileNotFoundException {
     
    		//    	File file = new File("src/in.txt");
    		//    	Scanner sc = new Scanner(file);
     
    		Scanner sc = new Scanner(System.in);
     
    		int N = sc.nextInt();
    		int[] A = new int[N];
    		for(int i=0;i<N;i++) {
    			A[i] = Integer.parseInt(sc.next());
    		}
    		sc.close();
    		int[] B = A.clone();
    		Arrays.sort(B);
    		int max = B[N-1];
    		int nextmax = B[N-2];
    		for(int i=0;i<N;i++) {
    			if(A[i]==max) {
    				System.out.println(nextmax);
    			} else {
    				System.out.println(max);
    			}
    		}
    	}
    } import java.io.FileNotFoundException; FileNotFoundException java.io import java.util.Arrays; Arrays java.util import java.util.Scanner; Scanner java.util public class Main {
    	public static void main(String[] args) throws FileNotFoundException {
     
    		//    	File file = new File("src/in.txt");
    		//    	Scanner sc = new Scanner(file);
     
    		Scanner sc = new Scanner(System.in);
     
    		int N = sc.nextInt();
    		int[] A = new int[N];
    		for(int i=0;i<N;i++) {
    			A[i] = Integer.parseInt(sc.next());
    		}
    		sc.close();
    		int[] B = A.clone();
    		Arrays.sort(B);
    		int max = B[N-1];
    		int nextmax = B[N-2];
    		for(int i=0;i<N;i++) {
    			if(A[i]==max) {
    				System.out.println(nextmax);
    			} else {
    				System.out.println(max);
    			}
    		}
    	}
    } Main public static void main(String[] args) throws FileNotFoundException {
     
    		//    	File file = new File("src/in.txt");
    		//    	Scanner sc = new Scanner(file);
     
    		Scanner sc = new Scanner(System.in);
     
    		int N = sc.nextInt();
    		int[] A = new int[N];
    		for(int i=0;i<N;i++) {
    			A[i] = Integer.parseInt(sc.next());
    		}
    		sc.close();
    		int[] B = A.clone();
    		Arrays.sort(B);
    		int max = B[N-1];
    		int nextmax = B[N-2];
    		for(int i=0;i<N;i++) {
    			if(A[i]==max) {
    				System.out.println(nextmax);
    			} else {
    				System.out.println(max);
    			}
    		}
    	} main {
     
    		//    	File file = new File("src/in.txt");
    		//    	Scanner sc = new Scanner(file);
     
    		Scanner sc = new Scanner(System.in);
     
    		int N = sc.nextInt();
    		int[] A = new int[N];
    		for(int i=0;i<N;i++) {
    			A[i] = Integer.parseInt(sc.next());
    		}
    		sc.close();
    		int[] B = A.clone();
    		Arrays.sort(B);
    		int max = B[N-1];
    		int nextmax = B[N-2];
    		for(int i=0;i<N;i++) {
    			if(A[i]==max) {
    				System.out.println(nextmax);
    			} else {
    				System.out.println(max);
    			}
    		}
    	} 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 for(int i=0;i<N;i++) {
    			A[i] = Integer.parseInt(sc.next());
    		} int i=0; int i=0; i 0 i<N i N i++ i++ i {
    			A[i] = Integer.parseInt(sc.next());
    		} {
    			A[i] = Integer.parseInt(sc.next());
    		} A[i] = Integer.parseInt(sc.next()) A[i] A i Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc sc.close() sc.close sc int[] B = A.clone(); B A.clone() A.clone A Arrays.sort(B) Arrays.sort Arrays B int max = B[N-1]; max B[N-1] B N-1 N 1 int nextmax = B[N-2]; nextmax B[N-2] B N-2 N 2 for(int i=0;i<N;i++) {
    			if(A[i]==max) {
    				System.out.println(nextmax);
    			} else {
    				System.out.println(max);
    			}
    		} int i=0; int i=0; i 0 i<N i N i++ i++ i {
    			if(A[i]==max) {
    				System.out.println(nextmax);
    			} else {
    				System.out.println(max);
    			}
    		} {
    			if(A[i]==max) {
    				System.out.println(nextmax);
    			} else {
    				System.out.println(max);
    			}
    		} if(A[i]==max) {
    				System.out.println(nextmax);
    			} else {
    				System.out.println(max);
    			} A[i]==max A[i] A i max {
    				System.out.println(nextmax);
    			} System.out.println(nextmax) System.out.println System.out System System.out nextmax {
    				System.out.println(max);
    			} System.out.println(max) System.out.println System.out System System.out max String[] args args public class Main {
    	public static void main(String[] args) throws FileNotFoundException {
     
    		//    	File file = new File("src/in.txt");
    		//    	Scanner sc = new Scanner(file);
     
    		Scanner sc = new Scanner(System.in);
     
    		int N = sc.nextInt();
    		int[] A = new int[N];
    		for(int i=0;i<N;i++) {
    			A[i] = Integer.parseInt(sc.next());
    		}
    		sc.close();
    		int[] B = A.clone();
    		Arrays.sort(B);
    		int max = B[N-1];
    		int nextmax = B[N-2];
    		for(int i=0;i<N;i++) {
    			if(A[i]==max) {
    				System.out.println(nextmax);
    			} else {
    				System.out.println(max);
    			}
    		}
    	}
    } public class Main {
    	public static void main(String[] args) throws FileNotFoundException {
     
    		//    	File file = new File("src/in.txt");
    		//    	Scanner sc = new Scanner(file);
     
    		Scanner sc = new Scanner(System.in);
     
    		int N = sc.nextInt();
    		int[] A = new int[N];
    		for(int i=0;i<N;i++) {
    			A[i] = Integer.parseInt(sc.next());
    		}
    		sc.close();
    		int[] B = A.clone();
    		Arrays.sort(B);
    		int max = B[N-1];
    		int nextmax = B[N-2];
    		for(int i=0;i<N;i++) {
    			if(A[i]==max) {
    				System.out.println(nextmax);
    			} else {
    				System.out.println(max);
    			}
    		}
    	}
    } Main
    import java.io.FileNotFoundException;
    import java.util.Arrays;
    import java.util.Scanner;
     
    public class Main {
    	public static void main(String[] args) throws FileNotFoundException {
     
    		//    	File file = new File("src/in.txt");
    		//    	Scanner sc = new Scanner(file);
     
    		Scanner sc = new Scanner(System.in);
     
    		int N = sc.nextInt();
    		int[] A = new int[N];
    		for(int i=0;i<N;i++) {
    			A[i] = Integer.parseInt(sc.next());
    		}
    		sc.close();
    		int[] B = A.clone();
    		Arrays.sort(B);
    		int max = B[N-1];
    		int nextmax = B[N-2];
    		for(int i=0;i<N;i++) {
    			if(A[i]==max) {
    				System.out.println(nextmax);
    			} else {
    				System.out.println(max);
    			}
    		}
    	}
    }