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

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

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int N = sc.nextInt();
		int[] A = new int[N];
		Integer[] B = new Integer[N];
		for(int i=0;i<N;i++) {
			int a = sc.nextInt();
			A[i] = a;
			B[i] = a;
		}
		
		Arrays.sort(B, Comparator.reverseOrder());
		int max = B[0];
		int secMax = B[1];
		
		for(int i=0;i<N;i++) {
			int skipInt = A[i];
			if(max != skipInt) {
				System.out.println(max);
			}else {
				System.out.println(secMax);
			}
		}
		
		sc.close();	
	}
}