import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int[] a = new int[n];

		int max = Integer.MIN_VALUE;
		int subMax = Integer.MIN_VALUE;
		for(int i = 0; i < n; i++) {
			int temp = scan.nextInt();
			a[i] = temp;
			if(temp >= max) {
				subMax = max;
				max = temp;
			}else if(temp >= subMax) {
				subMax = temp;
			}
		}
		for(int i = 0; i < n; i++) {
			if(a[i] == max) {
				System.out.println(subMax);
			}else {
				System.out.println(max);
			}
		}
	}
} import java.util.Scanner; Scanner java.util public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int[] a = new int[n];

		int max = Integer.MIN_VALUE;
		int subMax = Integer.MIN_VALUE;
		for(int i = 0; i < n; i++) {
			int temp = scan.nextInt();
			a[i] = temp;
			if(temp >= max) {
				subMax = max;
				max = temp;
			}else if(temp >= subMax) {
				subMax = temp;
			}
		}
		for(int i = 0; i < n; i++) {
			if(a[i] == max) {
				System.out.println(subMax);
			}else {
				System.out.println(max);
			}
		}
	}
} Main public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int[] a = new int[n];

		int max = Integer.MIN_VALUE;
		int subMax = Integer.MIN_VALUE;
		for(int i = 0; i < n; i++) {
			int temp = scan.nextInt();
			a[i] = temp;
			if(temp >= max) {
				subMax = max;
				max = temp;
			}else if(temp >= subMax) {
				subMax = temp;
			}
		}
		for(int i = 0; i < n; i++) {
			if(a[i] == max) {
				System.out.println(subMax);
			}else {
				System.out.println(max);
			}
		}
	} main {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int[] a = new int[n];

		int max = Integer.MIN_VALUE;
		int subMax = Integer.MIN_VALUE;
		for(int i = 0; i < n; i++) {
			int temp = scan.nextInt();
			a[i] = temp;
			if(temp >= max) {
				subMax = max;
				max = temp;
			}else if(temp >= subMax) {
				subMax = temp;
			}
		}
		for(int i = 0; i < n; i++) {
			if(a[i] == max) {
				System.out.println(subMax);
			}else {
				System.out.println(max);
			}
		}
	} Scanner scan = new Scanner(System.in); scan 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 max = Integer.MIN_VALUE; max Integer.MIN_VALUE Integer Integer.MIN_VALUE int subMax = Integer.MIN_VALUE; subMax Integer.MIN_VALUE Integer Integer.MIN_VALUE for(int i = 0; i < n; i++) {
			int temp = scan.nextInt();
			a[i] = temp;
			if(temp >= max) {
				subMax = max;
				max = temp;
			}else if(temp >= subMax) {
				subMax = temp;
			}
		} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
			int temp = scan.nextInt();
			a[i] = temp;
			if(temp >= max) {
				subMax = max;
				max = temp;
			}else if(temp >= subMax) {
				subMax = temp;
			}
		} {
			int temp = scan.nextInt();
			a[i] = temp;
			if(temp >= max) {
				subMax = max;
				max = temp;
			}else if(temp >= subMax) {
				subMax = temp;
			}
		} int temp = scan.nextInt(); temp scan.nextInt() scan.nextInt scan a[i] = temp a[i] a i temp if(temp >= max) {
				subMax = max;
				max = temp;
			}else if(temp >= subMax) {
				subMax = temp;
			} temp >= max temp max {
				subMax = max;
				max = temp;
			} subMax = max subMax max max = temp max temp if(temp >= subMax) {
				subMax = temp;
			} temp >= subMax temp subMax {
				subMax = temp;
			} subMax = temp subMax temp for(int i = 0; i < n; i++) {
			if(a[i] == max) {
				System.out.println(subMax);
			}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(subMax);
			}else {
				System.out.println(max);
			}
		} {
			if(a[i] == max) {
				System.out.println(subMax);
			}else {
				System.out.println(max);
			}
		} if(a[i] == max) {
				System.out.println(subMax);
			}else {
				System.out.println(max);
			} a[i] == max a[i] a i max {
				System.out.println(subMax);
			} System.out.println(subMax) System.out.println System.out System System.out subMax {
				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) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int[] a = new int[n];

		int max = Integer.MIN_VALUE;
		int subMax = Integer.MIN_VALUE;
		for(int i = 0; i < n; i++) {
			int temp = scan.nextInt();
			a[i] = temp;
			if(temp >= max) {
				subMax = max;
				max = temp;
			}else if(temp >= subMax) {
				subMax = temp;
			}
		}
		for(int i = 0; i < n; i++) {
			if(a[i] == max) {
				System.out.println(subMax);
			}else {
				System.out.println(max);
			}
		}
	}
} public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int[] a = new int[n];

		int max = Integer.MIN_VALUE;
		int subMax = Integer.MIN_VALUE;
		for(int i = 0; i < n; i++) {
			int temp = scan.nextInt();
			a[i] = temp;
			if(temp >= max) {
				subMax = max;
				max = temp;
			}else if(temp >= subMax) {
				subMax = temp;
			}
		}
		for(int i = 0; i < n; i++) {
			if(a[i] == max) {
				System.out.println(subMax);
			}else {
				System.out.println(max);
			}
		}
	}
} Main
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int[] a = new int[n];

		int max = Integer.MIN_VALUE;
		int subMax = Integer.MIN_VALUE;
		for(int i = 0; i < n; i++) {
			int temp = scan.nextInt();
			a[i] = temp;
			if(temp >= max) {
				subMax = max;
				max = temp;
			}else if(temp >= subMax) {
				subMax = temp;
			}
		}
		for(int i = 0; i < n; i++) {
			if(a[i] == max) {
				System.out.println(subMax);
			}else {
				System.out.println(max);
			}
		}
	}
}
