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];
		for(int i = 0; i < N; i++) a[i] = sc.nextInt();
		int first = Integer.MIN_VALUE, second = Integer.MIN_VALUE;
		for(int i = 0; i < N; i++) {
			if(a[i] > first) {
				first = a[i];
			}else if(a[i] > second) {
				second = a[i];
			}
		}
		for(int i = 0; i < N; i++) {
			if(a[i] != first) System.out.println(first);
			else System.out.println(second);
		}
	}
} 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];
		for(int i = 0; i < N; i++) a[i] = sc.nextInt();
		int first = Integer.MIN_VALUE, second = Integer.MIN_VALUE;
		for(int i = 0; i < N; i++) {
			if(a[i] > first) {
				first = a[i];
			}else if(a[i] > second) {
				second = a[i];
			}
		}
		for(int i = 0; i < N; i++) {
			if(a[i] != first) System.out.println(first);
			else System.out.println(second);
		}
	}
} Main public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] a = new int[N];
		for(int i = 0; i < N; i++) a[i] = sc.nextInt();
		int first = Integer.MIN_VALUE, second = Integer.MIN_VALUE;
		for(int i = 0; i < N; i++) {
			if(a[i] > first) {
				first = a[i];
			}else if(a[i] > second) {
				second = a[i];
			}
		}
		for(int i = 0; i < N; i++) {
			if(a[i] != first) System.out.println(first);
			else System.out.println(second);
		}
	} main {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] a = new int[N];
		for(int i = 0; i < N; i++) a[i] = sc.nextInt();
		int first = Integer.MIN_VALUE, second = Integer.MIN_VALUE;
		for(int i = 0; i < N; i++) {
			if(a[i] > first) {
				first = a[i];
			}else if(a[i] > second) {
				second = a[i];
			}
		}
		for(int i = 0; i < N; i++) {
			if(a[i] != first) System.out.println(first);
			else System.out.println(second);
		}
	} 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] = 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] a i sc.nextInt() sc.nextInt sc int first = Integer.MIN_VALUE first Integer.MIN_VALUE Integer Integer.MIN_VALUE second = Integer.MIN_VALUE; second Integer.MIN_VALUE Integer Integer.MIN_VALUE for(int i = 0; i < N; i++) {
			if(a[i] > first) {
				first = a[i];
			}else if(a[i] > second) {
				second = a[i];
			}
		} int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
			if(a[i] > first) {
				first = a[i];
			}else if(a[i] > second) {
				second = a[i];
			}
		} {
			if(a[i] > first) {
				first = a[i];
			}else if(a[i] > second) {
				second = a[i];
			}
		} if(a[i] > first) {
				first = a[i];
			}else if(a[i] > second) {
				second = a[i];
			} a[i] > first a[i] a i first {
				first = a[i];
			} first = a[i] first a[i] a i if(a[i] > second) {
				second = a[i];
			} a[i] > second a[i] a i second {
				second = a[i];
			} second = a[i] second a[i] a i for(int i = 0; i < N; i++) {
			if(a[i] != first) System.out.println(first);
			else System.out.println(second);
		} int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
			if(a[i] != first) System.out.println(first);
			else System.out.println(second);
		} {
			if(a[i] != first) System.out.println(first);
			else System.out.println(second);
		} if(a[i] != first) System.out.println(first);
			else System.out.println(second); a[i] != first a[i] a i first System.out.println(first) System.out.println System.out System System.out first System.out.println(second) System.out.println System.out System System.out second 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];
		for(int i = 0; i < N; i++) a[i] = sc.nextInt();
		int first = Integer.MIN_VALUE, second = Integer.MIN_VALUE;
		for(int i = 0; i < N; i++) {
			if(a[i] > first) {
				first = a[i];
			}else if(a[i] > second) {
				second = a[i];
			}
		}
		for(int i = 0; i < N; i++) {
			if(a[i] != first) System.out.println(first);
			else System.out.println(second);
		}
	}
} public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] a = new int[N];
		for(int i = 0; i < N; i++) a[i] = sc.nextInt();
		int first = Integer.MIN_VALUE, second = Integer.MIN_VALUE;
		for(int i = 0; i < N; i++) {
			if(a[i] > first) {
				first = a[i];
			}else if(a[i] > second) {
				second = a[i];
			}
		}
		for(int i = 0; i < N; i++) {
			if(a[i] != first) System.out.println(first);
			else System.out.println(second);
		}
	}
} Main
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];
		for(int i = 0; i < N; i++) a[i] = sc.nextInt();
		int first = Integer.MIN_VALUE, second = Integer.MIN_VALUE;
		for(int i = 0; i < N; i++) {
			if(a[i] > first) {
				first = a[i];
			}else if(a[i] > second) {
				second = a[i];
			}
		}
		for(int i = 0; i < N; i++) {
			if(a[i] != first) System.out.println(first);
			else System.out.println(second);
		}
	}
}
