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 = Integer.parseInt(sc.next());
		int[] A = new int[N];
		int[] sortedA = new int[N];
		int idx;
		for (idx = 0; idx < N; idx++) {
			A[idx] = Integer.parseInt(sc.next());
			sortedA[idx] = A[idx];
		}
//		Arrays.parallelSort(sortedA);
		Arrays.sort(sortedA);

		int max = sortedA[N - 1];
		int second = sortedA[N - 2];

		for (idx = 0; idx < N; idx++) {
			if (A[idx] == max) {
				System.out.println(second);
			} 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) {

		Scanner sc = new Scanner(System.in);

		int N = Integer.parseInt(sc.next());
		int[] A = new int[N];
		int[] sortedA = new int[N];
		int idx;
		for (idx = 0; idx < N; idx++) {
			A[idx] = Integer.parseInt(sc.next());
			sortedA[idx] = A[idx];
		}
//		Arrays.parallelSort(sortedA);
		Arrays.sort(sortedA);

		int max = sortedA[N - 1];
		int second = sortedA[N - 2];

		for (idx = 0; idx < N; idx++) {
			if (A[idx] == max) {
				System.out.println(second);
			} else {
				System.out.println(max);
			}
		}

	}

} Main public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int N = Integer.parseInt(sc.next());
		int[] A = new int[N];
		int[] sortedA = new int[N];
		int idx;
		for (idx = 0; idx < N; idx++) {
			A[idx] = Integer.parseInt(sc.next());
			sortedA[idx] = A[idx];
		}
//		Arrays.parallelSort(sortedA);
		Arrays.sort(sortedA);

		int max = sortedA[N - 1];
		int second = sortedA[N - 2];

		for (idx = 0; idx < N; idx++) {
			if (A[idx] == max) {
				System.out.println(second);
			} else {
				System.out.println(max);
			}
		}

	} main {

		Scanner sc = new Scanner(System.in);

		int N = Integer.parseInt(sc.next());
		int[] A = new int[N];
		int[] sortedA = new int[N];
		int idx;
		for (idx = 0; idx < N; idx++) {
			A[idx] = Integer.parseInt(sc.next());
			sortedA[idx] = A[idx];
		}
//		Arrays.parallelSort(sortedA);
		Arrays.sort(sortedA);

		int max = sortedA[N - 1];
		int second = sortedA[N - 2];

		for (idx = 0; idx < N; idx++) {
			if (A[idx] == max) {
				System.out.println(second);
			} else {
				System.out.println(max);
			}
		}

	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int N = Integer.parseInt(sc.next()); N Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc int[] A = new int[N]; A new int[N] N int[] sortedA = new int[N]; sortedA new int[N] N int idx; idx for (idx = 0; idx < N; idx++) {
			A[idx] = Integer.parseInt(sc.next());
			sortedA[idx] = A[idx];
		} idx = 0; idx = 0 idx 0 idx < N idx N idx++ idx++ idx {
			A[idx] = Integer.parseInt(sc.next());
			sortedA[idx] = A[idx];
		} {
			A[idx] = Integer.parseInt(sc.next());
			sortedA[idx] = A[idx];
		} A[idx] = Integer.parseInt(sc.next()) A[idx] A idx Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc sortedA[idx] = A[idx] sortedA[idx] sortedA idx A[idx] A idx Arrays.sort(sortedA) Arrays.sort Arrays sortedA int max = sortedA[N - 1]; max sortedA[N - 1] sortedA N - 1 N 1 int second = sortedA[N - 2]; second sortedA[N - 2] sortedA N - 2 N 2 for (idx = 0; idx < N; idx++) {
			if (A[idx] == max) {
				System.out.println(second);
			} else {
				System.out.println(max);
			}
		} idx = 0; idx = 0 idx 0 idx < N idx N idx++ idx++ idx {
			if (A[idx] == max) {
				System.out.println(second);
			} else {
				System.out.println(max);
			}
		} {
			if (A[idx] == max) {
				System.out.println(second);
			} else {
				System.out.println(max);
			}
		} if (A[idx] == max) {
				System.out.println(second);
			} else {
				System.out.println(max);
			} A[idx] == max A[idx] A idx max {
				System.out.println(second);
			} System.out.println(second) System.out.println System.out System System.out second {
				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 sc = new Scanner(System.in);

		int N = Integer.parseInt(sc.next());
		int[] A = new int[N];
		int[] sortedA = new int[N];
		int idx;
		for (idx = 0; idx < N; idx++) {
			A[idx] = Integer.parseInt(sc.next());
			sortedA[idx] = A[idx];
		}
//		Arrays.parallelSort(sortedA);
		Arrays.sort(sortedA);

		int max = sortedA[N - 1];
		int second = sortedA[N - 2];

		for (idx = 0; idx < N; idx++) {
			if (A[idx] == max) {
				System.out.println(second);
			} else {
				System.out.println(max);
			}
		}

	}

} public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int N = Integer.parseInt(sc.next());
		int[] A = new int[N];
		int[] sortedA = new int[N];
		int idx;
		for (idx = 0; idx < N; idx++) {
			A[idx] = Integer.parseInt(sc.next());
			sortedA[idx] = A[idx];
		}
//		Arrays.parallelSort(sortedA);
		Arrays.sort(sortedA);

		int max = sortedA[N - 1];
		int second = sortedA[N - 2];

		for (idx = 0; idx < N; idx++) {
			if (A[idx] == max) {
				System.out.println(second);
			} else {
				System.out.println(max);
			}
		}

	}

} 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 = Integer.parseInt(sc.next());
		int[] A = new int[N];
		int[] sortedA = new int[N];
		int idx;
		for (idx = 0; idx < N; idx++) {
			A[idx] = Integer.parseInt(sc.next());
			sortedA[idx] = A[idx];
		}
//		Arrays.parallelSort(sortedA);
		Arrays.sort(sortedA);

		int max = sortedA[N - 1];
		int second = sortedA[N - 2];

		for (idx = 0; idx < N; idx++) {
			if (A[idx] == max) {
				System.out.println(second);
			} else {
				System.out.println(max);
			}
		}

	}

}
