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

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		Integer A[] = new Integer[N];
		Integer B[] = new Integer[N];
		int max = 0;
		for (int i = 0; i < N; i++) {
			A[i] = sc.nextInt();
			if (A[i] > max) {
				max = A[i];
			}
		}
		sc.close();

		for (int i = 0; i < N; i++) {
			B[i] = A[i];
		}
		Arrays.sort(B, Collections.reverseOrder());

		for (int i = 0; i < N; i++) {
			if (A[i] == max) {
				System.out.println(B[1]);
			} else {
				System.out.println(max);
			}
		}
	}
} import java.util.Arrays; Arrays java.util import java.util.Collections; Collections 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();
		Integer A[] = new Integer[N];
		Integer B[] = new Integer[N];
		int max = 0;
		for (int i = 0; i < N; i++) {
			A[i] = sc.nextInt();
			if (A[i] > max) {
				max = A[i];
			}
		}
		sc.close();

		for (int i = 0; i < N; i++) {
			B[i] = A[i];
		}
		Arrays.sort(B, Collections.reverseOrder());

		for (int i = 0; i < N; i++) {
			if (A[i] == max) {
				System.out.println(B[1]);
			} else {
				System.out.println(max);
			}
		}
	}
} Main public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		Integer A[] = new Integer[N];
		Integer B[] = new Integer[N];
		int max = 0;
		for (int i = 0; i < N; i++) {
			A[i] = sc.nextInt();
			if (A[i] > max) {
				max = A[i];
			}
		}
		sc.close();

		for (int i = 0; i < N; i++) {
			B[i] = A[i];
		}
		Arrays.sort(B, Collections.reverseOrder());

		for (int i = 0; i < N; i++) {
			if (A[i] == max) {
				System.out.println(B[1]);
			} else {
				System.out.println(max);
			}
		}
	} main {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		Integer A[] = new Integer[N];
		Integer B[] = new Integer[N];
		int max = 0;
		for (int i = 0; i < N; i++) {
			A[i] = sc.nextInt();
			if (A[i] > max) {
				max = A[i];
			}
		}
		sc.close();

		for (int i = 0; i < N; i++) {
			B[i] = A[i];
		}
		Arrays.sort(B, Collections.reverseOrder());

		for (int i = 0; i < N; i++) {
			if (A[i] == max) {
				System.out.println(B[1]);
			} else {
				System.out.println(max);
			}
		}
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int N = sc.nextInt(); N sc.nextInt() sc.nextInt sc Integer A[] = new Integer[N]; A new Integer[N] N Integer B[] = new Integer[N]; B new Integer[N] N int max = 0; max 0 for (int i = 0; i < N; i++) {
			A[i] = sc.nextInt();
			if (A[i] > max) {
				max = A[i];
			}
		} int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
			A[i] = sc.nextInt();
			if (A[i] > max) {
				max = A[i];
			}
		} {
			A[i] = sc.nextInt();
			if (A[i] > max) {
				max = A[i];
			}
		} A[i] = sc.nextInt() A[i] A i sc.nextInt() sc.nextInt sc if (A[i] > max) {
				max = A[i];
			} A[i] > max A[i] A i max {
				max = A[i];
			} max = A[i] max A[i] A i sc.close() sc.close sc for (int i = 0; i < N; i++) {
			B[i] = A[i];
		} int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
			B[i] = A[i];
		} {
			B[i] = A[i];
		} B[i] = A[i] B[i] B i A[i] A i Arrays.sort(B, Collections.reverseOrder()) Arrays.sort Arrays B Collections.reverseOrder() Collections.reverseOrder Collections for (int i = 0; i < N; i++) {
			if (A[i] == max) {
				System.out.println(B[1]);
			} 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(B[1]);
			} else {
				System.out.println(max);
			}
		} {
			if (A[i] == max) {
				System.out.println(B[1]);
			} else {
				System.out.println(max);
			}
		} if (A[i] == max) {
				System.out.println(B[1]);
			} else {
				System.out.println(max);
			} A[i] == max A[i] A i max {
				System.out.println(B[1]);
			} System.out.println(B[1]) System.out.println System.out System System.out B[1] B 1 {
				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 = sc.nextInt();
		Integer A[] = new Integer[N];
		Integer B[] = new Integer[N];
		int max = 0;
		for (int i = 0; i < N; i++) {
			A[i] = sc.nextInt();
			if (A[i] > max) {
				max = A[i];
			}
		}
		sc.close();

		for (int i = 0; i < N; i++) {
			B[i] = A[i];
		}
		Arrays.sort(B, Collections.reverseOrder());

		for (int i = 0; i < N; i++) {
			if (A[i] == max) {
				System.out.println(B[1]);
			} else {
				System.out.println(max);
			}
		}
	}
} public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		Integer A[] = new Integer[N];
		Integer B[] = new Integer[N];
		int max = 0;
		for (int i = 0; i < N; i++) {
			A[i] = sc.nextInt();
			if (A[i] > max) {
				max = A[i];
			}
		}
		sc.close();

		for (int i = 0; i < N; i++) {
			B[i] = A[i];
		}
		Arrays.sort(B, Collections.reverseOrder());

		for (int i = 0; i < N; i++) {
			if (A[i] == max) {
				System.out.println(B[1]);
			} else {
				System.out.println(max);
			}
		}
	}
} Main
import java.util.Arrays;
import java.util.Collections;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		Integer A[] = new Integer[N];
		Integer B[] = new Integer[N];
		int max = 0;
		for (int i = 0; i < N; i++) {
			A[i] = sc.nextInt();
			if (A[i] > max) {
				max = A[i];
			}
		}
		sc.close();

		for (int i = 0; i < N; i++) {
			B[i] = A[i];
		}
		Arrays.sort(B, Collections.reverseOrder());

		for (int i = 0; i < N; i++) {
			if (A[i] == max) {
				System.out.println(B[1]);
			} else {
				System.out.println(max);
			}
		}
	}
}
