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

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] nums = new int[N];
		long sum = 0;
		int max =0;
		for (int i = 0; i < N; i++) {
			nums[i] = sc.nextInt();
			max = Math.max(max, nums[i]);
		}

		int[] nums2 = Arrays.copyOf(nums, N);;
		Arrays.sort(nums2);
		int max2 = nums2[N-2];

		for (int i = 0; i < N; i++) {
			if (nums[i] != max) {
				System.out.println(max);
			} else {
				System.out.println(max2);
			}
		}


	}
}

 import java.util.Arrays; Arrays 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[] nums = new int[N];
		long sum = 0;
		int max =0;
		for (int i = 0; i < N; i++) {
			nums[i] = sc.nextInt();
			max = Math.max(max, nums[i]);
		}

		int[] nums2 = Arrays.copyOf(nums, N);;
		Arrays.sort(nums2);
		int max2 = nums2[N-2];

		for (int i = 0; i < N; i++) {
			if (nums[i] != max) {
				System.out.println(max);
			} else {
				System.out.println(max2);
			}
		}


	}
} Main public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] nums = new int[N];
		long sum = 0;
		int max =0;
		for (int i = 0; i < N; i++) {
			nums[i] = sc.nextInt();
			max = Math.max(max, nums[i]);
		}

		int[] nums2 = Arrays.copyOf(nums, N);;
		Arrays.sort(nums2);
		int max2 = nums2[N-2];

		for (int i = 0; i < N; i++) {
			if (nums[i] != max) {
				System.out.println(max);
			} else {
				System.out.println(max2);
			}
		}


	} main {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] nums = new int[N];
		long sum = 0;
		int max =0;
		for (int i = 0; i < N; i++) {
			nums[i] = sc.nextInt();
			max = Math.max(max, nums[i]);
		}

		int[] nums2 = Arrays.copyOf(nums, N);;
		Arrays.sort(nums2);
		int max2 = nums2[N-2];

		for (int i = 0; i < N; i++) {
			if (nums[i] != max) {
				System.out.println(max);
			} else {
				System.out.println(max2);
			}
		}


	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int N = sc.nextInt(); N sc.nextInt() sc.nextInt sc int[] nums = new int[N]; nums new int[N] N long sum = 0; sum 0 int max =0; max 0 for (int i = 0; i < N; i++) {
			nums[i] = sc.nextInt();
			max = Math.max(max, nums[i]);
		} int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
			nums[i] = sc.nextInt();
			max = Math.max(max, nums[i]);
		} {
			nums[i] = sc.nextInt();
			max = Math.max(max, nums[i]);
		} nums[i] = sc.nextInt() nums[i] nums i sc.nextInt() sc.nextInt sc max = Math.max(max, nums[i]) max Math.max(max, nums[i]) Math.max Math max nums[i] nums i int[] nums2 = Arrays.copyOf(nums, N); nums2 Arrays.copyOf(nums, N) Arrays.copyOf Arrays nums N Arrays.sort(nums2) Arrays.sort Arrays nums2 int max2 = nums2[N-2]; max2 nums2[N-2] nums2 N-2 N 2 for (int i = 0; i < N; i++) {
			if (nums[i] != max) {
				System.out.println(max);
			} else {
				System.out.println(max2);
			}
		} int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
			if (nums[i] != max) {
				System.out.println(max);
			} else {
				System.out.println(max2);
			}
		} {
			if (nums[i] != max) {
				System.out.println(max);
			} else {
				System.out.println(max2);
			}
		} if (nums[i] != max) {
				System.out.println(max);
			} else {
				System.out.println(max2);
			} nums[i] != max nums[i] nums i max {
				System.out.println(max);
			} System.out.println(max) System.out.println System.out System System.out max {
				System.out.println(max2);
			} System.out.println(max2) System.out.println System.out System System.out max2 String[] args args public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] nums = new int[N];
		long sum = 0;
		int max =0;
		for (int i = 0; i < N; i++) {
			nums[i] = sc.nextInt();
			max = Math.max(max, nums[i]);
		}

		int[] nums2 = Arrays.copyOf(nums, N);;
		Arrays.sort(nums2);
		int max2 = nums2[N-2];

		for (int i = 0; i < N; i++) {
			if (nums[i] != max) {
				System.out.println(max);
			} else {
				System.out.println(max2);
			}
		}


	}
} public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] nums = new int[N];
		long sum = 0;
		int max =0;
		for (int i = 0; i < N; i++) {
			nums[i] = sc.nextInt();
			max = Math.max(max, nums[i]);
		}

		int[] nums2 = Arrays.copyOf(nums, N);;
		Arrays.sort(nums2);
		int max2 = nums2[N-2];

		for (int i = 0; i < N; i++) {
			if (nums[i] != max) {
				System.out.println(max);
			} else {
				System.out.println(max2);
			}
		}


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

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] nums = new int[N];
		long sum = 0;
		int max =0;
		for (int i = 0; i < N; i++) {
			nums[i] = sc.nextInt();
			max = Math.max(max, nums[i]);
		}

		int[] nums2 = Arrays.copyOf(nums, N);;
		Arrays.sort(nums2);
		int max2 = nums2[N-2];

		for (int i = 0; i < N; i++) {
			if (nums[i] != max) {
				System.out.println(max);
			} else {
				System.out.println(max2);
			}
		}


	}
}


