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];

		int num, maxNum = -1, nextMaxNum = -1;
		boolean duplicate = false;
		for (int i = 0; i < N; i++) {
			num = sc.nextInt();

			if (num > maxNum) {
				nextMaxNum = maxNum;
				maxNum = num;
				duplicate = false;
			} else if (num == maxNum) {
				duplicate = true;
			} else {
				nextMaxNum = Math.max(nextMaxNum, num);
			}
			A[i] = num;
		}

		for (int i = 0; i < N; i++) {
			if (A[i] == maxNum && !duplicate) {
				System.out.println(nextMaxNum);
			} else {
				System.out.println(maxNum);
			}
		}
	}

} 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];

		int num, maxNum = -1, nextMaxNum = -1;
		boolean duplicate = false;
		for (int i = 0; i < N; i++) {
			num = sc.nextInt();

			if (num > maxNum) {
				nextMaxNum = maxNum;
				maxNum = num;
				duplicate = false;
			} else if (num == maxNum) {
				duplicate = true;
			} else {
				nextMaxNum = Math.max(nextMaxNum, num);
			}
			A[i] = num;
		}

		for (int i = 0; i < N; i++) {
			if (A[i] == maxNum && !duplicate) {
				System.out.println(nextMaxNum);
			} else {
				System.out.println(maxNum);
			}
		}
	}

} Main public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] A = new int[N];

		int num, maxNum = -1, nextMaxNum = -1;
		boolean duplicate = false;
		for (int i = 0; i < N; i++) {
			num = sc.nextInt();

			if (num > maxNum) {
				nextMaxNum = maxNum;
				maxNum = num;
				duplicate = false;
			} else if (num == maxNum) {
				duplicate = true;
			} else {
				nextMaxNum = Math.max(nextMaxNum, num);
			}
			A[i] = num;
		}

		for (int i = 0; i < N; i++) {
			if (A[i] == maxNum && !duplicate) {
				System.out.println(nextMaxNum);
			} else {
				System.out.println(maxNum);
			}
		}
	} main {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] A = new int[N];

		int num, maxNum = -1, nextMaxNum = -1;
		boolean duplicate = false;
		for (int i = 0; i < N; i++) {
			num = sc.nextInt();

			if (num > maxNum) {
				nextMaxNum = maxNum;
				maxNum = num;
				duplicate = false;
			} else if (num == maxNum) {
				duplicate = true;
			} else {
				nextMaxNum = Math.max(nextMaxNum, num);
			}
			A[i] = num;
		}

		for (int i = 0; i < N; i++) {
			if (A[i] == maxNum && !duplicate) {
				System.out.println(nextMaxNum);
			} else {
				System.out.println(maxNum);
			}
		}
	} 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 int num num maxNum = -1 maxNum -1 1 nextMaxNum = -1; nextMaxNum -1 1 boolean duplicate = false; duplicate false for (int i = 0; i < N; i++) {
			num = sc.nextInt();

			if (num > maxNum) {
				nextMaxNum = maxNum;
				maxNum = num;
				duplicate = false;
			} else if (num == maxNum) {
				duplicate = true;
			} else {
				nextMaxNum = Math.max(nextMaxNum, num);
			}
			A[i] = num;
		} int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
			num = sc.nextInt();

			if (num > maxNum) {
				nextMaxNum = maxNum;
				maxNum = num;
				duplicate = false;
			} else if (num == maxNum) {
				duplicate = true;
			} else {
				nextMaxNum = Math.max(nextMaxNum, num);
			}
			A[i] = num;
		} {
			num = sc.nextInt();

			if (num > maxNum) {
				nextMaxNum = maxNum;
				maxNum = num;
				duplicate = false;
			} else if (num == maxNum) {
				duplicate = true;
			} else {
				nextMaxNum = Math.max(nextMaxNum, num);
			}
			A[i] = num;
		} num = sc.nextInt() num sc.nextInt() sc.nextInt sc if (num > maxNum) {
				nextMaxNum = maxNum;
				maxNum = num;
				duplicate = false;
			} else if (num == maxNum) {
				duplicate = true;
			} else {
				nextMaxNum = Math.max(nextMaxNum, num);
			} num > maxNum num maxNum {
				nextMaxNum = maxNum;
				maxNum = num;
				duplicate = false;
			} nextMaxNum = maxNum nextMaxNum maxNum maxNum = num maxNum num duplicate = false duplicate false if (num == maxNum) {
				duplicate = true;
			} else {
				nextMaxNum = Math.max(nextMaxNum, num);
			} num == maxNum num maxNum {
				duplicate = true;
			} duplicate = true duplicate true {
				nextMaxNum = Math.max(nextMaxNum, num);
			} nextMaxNum = Math.max(nextMaxNum, num) nextMaxNum Math.max(nextMaxNum, num) Math.max Math nextMaxNum num A[i] = num A[i] A i num for (int i = 0; i < N; i++) {
			if (A[i] == maxNum && !duplicate) {
				System.out.println(nextMaxNum);
			} else {
				System.out.println(maxNum);
			}
		} int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
			if (A[i] == maxNum && !duplicate) {
				System.out.println(nextMaxNum);
			} else {
				System.out.println(maxNum);
			}
		} {
			if (A[i] == maxNum && !duplicate) {
				System.out.println(nextMaxNum);
			} else {
				System.out.println(maxNum);
			}
		} if (A[i] == maxNum && !duplicate) {
				System.out.println(nextMaxNum);
			} else {
				System.out.println(maxNum);
			} A[i] == maxNum && !duplicate A[i] == maxNum A[i] A i maxNum !duplicate duplicate {
				System.out.println(nextMaxNum);
			} System.out.println(nextMaxNum) System.out.println System.out System System.out nextMaxNum {
				System.out.println(maxNum);
			} System.out.println(maxNum) System.out.println System.out System System.out maxNum 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];

		int num, maxNum = -1, nextMaxNum = -1;
		boolean duplicate = false;
		for (int i = 0; i < N; i++) {
			num = sc.nextInt();

			if (num > maxNum) {
				nextMaxNum = maxNum;
				maxNum = num;
				duplicate = false;
			} else if (num == maxNum) {
				duplicate = true;
			} else {
				nextMaxNum = Math.max(nextMaxNum, num);
			}
			A[i] = num;
		}

		for (int i = 0; i < N; i++) {
			if (A[i] == maxNum && !duplicate) {
				System.out.println(nextMaxNum);
			} else {
				System.out.println(maxNum);
			}
		}
	}

} public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] A = new int[N];

		int num, maxNum = -1, nextMaxNum = -1;
		boolean duplicate = false;
		for (int i = 0; i < N; i++) {
			num = sc.nextInt();

			if (num > maxNum) {
				nextMaxNum = maxNum;
				maxNum = num;
				duplicate = false;
			} else if (num == maxNum) {
				duplicate = true;
			} else {
				nextMaxNum = Math.max(nextMaxNum, num);
			}
			A[i] = num;
		}

		for (int i = 0; i < N; i++) {
			if (A[i] == maxNum && !duplicate) {
				System.out.println(nextMaxNum);
			} else {
				System.out.println(maxNum);
			}
		}
	}

} 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];

		int num, maxNum = -1, nextMaxNum = -1;
		boolean duplicate = false;
		for (int i = 0; i < N; i++) {
			num = sc.nextInt();

			if (num > maxNum) {
				nextMaxNum = maxNum;
				maxNum = num;
				duplicate = false;
			} else if (num == maxNum) {
				duplicate = true;
			} else {
				nextMaxNum = Math.max(nextMaxNum, num);
			}
			A[i] = num;
		}

		for (int i = 0; i < N; i++) {
			if (A[i] == maxNum && !duplicate) {
				System.out.println(nextMaxNum);
			} else {
				System.out.println(maxNum);
			}
		}
	}

}
