import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[]args) {
		try(Scanner scan = new Scanner(System.in)){
			
			int N = scan.nextInt();
			int[]A = new int[N];
			int[]B = new int[N];
			for(int i = 0;i<N;i++) {
				A[i] = scan.nextInt();
				B[i] = A[i];
			}
			Arrays.sort(B);
			int max = B[N-1];
			int  maxdub = 0;
			if(B[N-2]==max)maxdub =1;
			
			for(int i = 0;i<N;i++) {
				if(A[i]<max) {
					System.out.println(max);
				}else{
					if(maxdub==0) {
						System.out.println(B[N-2]);
					}else{
						System.out.println(max);
					}
				}
			}
			
		}
		
		
	}
		

} import java.util.Arrays; Arrays java.util import java.util.Scanner; Scanner java.util public class Main {
	public static void main(String[]args) {
		try(Scanner scan = new Scanner(System.in)){
			
			int N = scan.nextInt();
			int[]A = new int[N];
			int[]B = new int[N];
			for(int i = 0;i<N;i++) {
				A[i] = scan.nextInt();
				B[i] = A[i];
			}
			Arrays.sort(B);
			int max = B[N-1];
			int  maxdub = 0;
			if(B[N-2]==max)maxdub =1;
			
			for(int i = 0;i<N;i++) {
				if(A[i]<max) {
					System.out.println(max);
				}else{
					if(maxdub==0) {
						System.out.println(B[N-2]);
					}else{
						System.out.println(max);
					}
				}
			}
			
		}
		
		
	}
		

} Main public static void main(String[]args) {
		try(Scanner scan = new Scanner(System.in)){
			
			int N = scan.nextInt();
			int[]A = new int[N];
			int[]B = new int[N];
			for(int i = 0;i<N;i++) {
				A[i] = scan.nextInt();
				B[i] = A[i];
			}
			Arrays.sort(B);
			int max = B[N-1];
			int  maxdub = 0;
			if(B[N-2]==max)maxdub =1;
			
			for(int i = 0;i<N;i++) {
				if(A[i]<max) {
					System.out.println(max);
				}else{
					if(maxdub==0) {
						System.out.println(B[N-2]);
					}else{
						System.out.println(max);
					}
				}
			}
			
		}
		
		
	} main {
		try(Scanner scan = new Scanner(System.in)){
			
			int N = scan.nextInt();
			int[]A = new int[N];
			int[]B = new int[N];
			for(int i = 0;i<N;i++) {
				A[i] = scan.nextInt();
				B[i] = A[i];
			}
			Arrays.sort(B);
			int max = B[N-1];
			int  maxdub = 0;
			if(B[N-2]==max)maxdub =1;
			
			for(int i = 0;i<N;i++) {
				if(A[i]<max) {
					System.out.println(max);
				}else{
					if(maxdub==0) {
						System.out.println(B[N-2]);
					}else{
						System.out.println(max);
					}
				}
			}
			
		}
		
		
	} try(Scanner scan = new Scanner(System.in)){
			
			int N = scan.nextInt();
			int[]A = new int[N];
			int[]B = new int[N];
			for(int i = 0;i<N;i++) {
				A[i] = scan.nextInt();
				B[i] = A[i];
			}
			Arrays.sort(B);
			int max = B[N-1];
			int  maxdub = 0;
			if(B[N-2]==max)maxdub =1;
			
			for(int i = 0;i<N;i++) {
				if(A[i]<max) {
					System.out.println(max);
				}else{
					if(maxdub==0) {
						System.out.println(B[N-2]);
					}else{
						System.out.println(max);
					}
				}
			}
			
		} {
			
			int N = scan.nextInt();
			int[]A = new int[N];
			int[]B = new int[N];
			for(int i = 0;i<N;i++) {
				A[i] = scan.nextInt();
				B[i] = A[i];
			}
			Arrays.sort(B);
			int max = B[N-1];
			int  maxdub = 0;
			if(B[N-2]==max)maxdub =1;
			
			for(int i = 0;i<N;i++) {
				if(A[i]<max) {
					System.out.println(max);
				}else{
					if(maxdub==0) {
						System.out.println(B[N-2]);
					}else{
						System.out.println(max);
					}
				}
			}
			
		} Scanner scan = new Scanner(System.in) Scanner scan = new Scanner(System.in) new Scanner(System.in) int N = scan.nextInt(); N scan.nextInt() scan.nextInt scan 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++) {
				A[i] = scan.nextInt();
				B[i] = A[i];
			} int i = 0; int i = 0; i 0 i<N i N i++ i++ i {
				A[i] = scan.nextInt();
				B[i] = A[i];
			} {
				A[i] = scan.nextInt();
				B[i] = A[i];
			} A[i] = scan.nextInt() A[i] A i scan.nextInt() scan.nextInt scan B[i] = A[i] B[i] B i A[i] A i Arrays.sort(B) Arrays.sort Arrays B int max = B[N-1]; max B[N-1] B N-1 N 1 int  maxdub = 0; maxdub 0 if(B[N-2]==max)maxdub =1; B[N-2]==max B[N-2] B N-2 N 2 max maxdub =1 maxdub 1 for(int i = 0;i<N;i++) {
				if(A[i]<max) {
					System.out.println(max);
				}else{
					if(maxdub==0) {
						System.out.println(B[N-2]);
					}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(max);
				}else{
					if(maxdub==0) {
						System.out.println(B[N-2]);
					}else{
						System.out.println(max);
					}
				}
			} {
				if(A[i]<max) {
					System.out.println(max);
				}else{
					if(maxdub==0) {
						System.out.println(B[N-2]);
					}else{
						System.out.println(max);
					}
				}
			} if(A[i]<max) {
					System.out.println(max);
				}else{
					if(maxdub==0) {
						System.out.println(B[N-2]);
					}else{
						System.out.println(max);
					}
				} A[i]<max A[i] A i max {
					System.out.println(max);
				} System.out.println(max) System.out.println System.out System System.out max {
					if(maxdub==0) {
						System.out.println(B[N-2]);
					}else{
						System.out.println(max);
					}
				} if(maxdub==0) {
						System.out.println(B[N-2]);
					}else{
						System.out.println(max);
					} maxdub==0 maxdub 0 {
						System.out.println(B[N-2]);
					} System.out.println(B[N-2]) System.out.println System.out System System.out B[N-2] B N-2 N 2 {
						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) {
		try(Scanner scan = new Scanner(System.in)){
			
			int N = scan.nextInt();
			int[]A = new int[N];
			int[]B = new int[N];
			for(int i = 0;i<N;i++) {
				A[i] = scan.nextInt();
				B[i] = A[i];
			}
			Arrays.sort(B);
			int max = B[N-1];
			int  maxdub = 0;
			if(B[N-2]==max)maxdub =1;
			
			for(int i = 0;i<N;i++) {
				if(A[i]<max) {
					System.out.println(max);
				}else{
					if(maxdub==0) {
						System.out.println(B[N-2]);
					}else{
						System.out.println(max);
					}
				}
			}
			
		}
		
		
	}
		

} public class Main {
	public static void main(String[]args) {
		try(Scanner scan = new Scanner(System.in)){
			
			int N = scan.nextInt();
			int[]A = new int[N];
			int[]B = new int[N];
			for(int i = 0;i<N;i++) {
				A[i] = scan.nextInt();
				B[i] = A[i];
			}
			Arrays.sort(B);
			int max = B[N-1];
			int  maxdub = 0;
			if(B[N-2]==max)maxdub =1;
			
			for(int i = 0;i<N;i++) {
				if(A[i]<max) {
					System.out.println(max);
				}else{
					if(maxdub==0) {
						System.out.println(B[N-2]);
					}else{
						System.out.println(max);
					}
				}
			}
			
		}
		
		
	}
		

} Main
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[]args) {
		try(Scanner scan = new Scanner(System.in)){
			
			int N = scan.nextInt();
			int[]A = new int[N];
			int[]B = new int[N];
			for(int i = 0;i<N;i++) {
				A[i] = scan.nextInt();
				B[i] = A[i];
			}
			Arrays.sort(B);
			int max = B[N-1];
			int  maxdub = 0;
			if(B[N-2]==max)maxdub =1;
			
			for(int i = 0;i<N;i++) {
				if(A[i]<max) {
					System.out.println(max);
				}else{
					if(maxdub==0) {
						System.out.println(B[N-2]);
					}else{
						System.out.println(max);
					}
				}
			}
			
		}
		
		
	}
		

}
