import 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 top1 = 0;
		int top2 = 0;
		for (int i = 0; i < N; i++) {
			A[i] = sc.nextInt();
			if (A[i] > top1) {
				top2 = top1;
				top1 = A[i];
			} else if (A[i] > top2) {
				top2 = A[i];
			}
		}
		sc.close();

		for (int i = 0; i < N; i++) {
			if (A[i] == top1) {
				System.out.println(top2);
			} else {
				System.out.println(top1);
			}
		}
	}
} import java.util.*; util.* java 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 top1 = 0;
		int top2 = 0;
		for (int i = 0; i < N; i++) {
			A[i] = sc.nextInt();
			if (A[i] > top1) {
				top2 = top1;
				top1 = A[i];
			} else if (A[i] > top2) {
				top2 = A[i];
			}
		}
		sc.close();

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

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

		for (int i = 0; i < N; i++) {
			if (A[i] == top1) {
				System.out.println(top2);
			} else {
				System.out.println(top1);
			}
		}
	} 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 top1 = 0; top1 0 int top2 = 0; top2 0 for (int i = 0; i < N; i++) {
			A[i] = sc.nextInt();
			if (A[i] > top1) {
				top2 = top1;
				top1 = A[i];
			} else if (A[i] > top2) {
				top2 = A[i];
			}
		} int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
			A[i] = sc.nextInt();
			if (A[i] > top1) {
				top2 = top1;
				top1 = A[i];
			} else if (A[i] > top2) {
				top2 = A[i];
			}
		} {
			A[i] = sc.nextInt();
			if (A[i] > top1) {
				top2 = top1;
				top1 = A[i];
			} else if (A[i] > top2) {
				top2 = A[i];
			}
		} A[i] = sc.nextInt() A[i] A i sc.nextInt() sc.nextInt sc if (A[i] > top1) {
				top2 = top1;
				top1 = A[i];
			} else if (A[i] > top2) {
				top2 = A[i];
			} A[i] > top1 A[i] A i top1 {
				top2 = top1;
				top1 = A[i];
			} top2 = top1 top2 top1 top1 = A[i] top1 A[i] A i if (A[i] > top2) {
				top2 = A[i];
			} A[i] > top2 A[i] A i top2 {
				top2 = A[i];
			} top2 = A[i] top2 A[i] A i sc.close() sc.close sc for (int i = 0; i < N; i++) {
			if (A[i] == top1) {
				System.out.println(top2);
			} else {
				System.out.println(top1);
			}
		} int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
			if (A[i] == top1) {
				System.out.println(top2);
			} else {
				System.out.println(top1);
			}
		} {
			if (A[i] == top1) {
				System.out.println(top2);
			} else {
				System.out.println(top1);
			}
		} if (A[i] == top1) {
				System.out.println(top2);
			} else {
				System.out.println(top1);
			} A[i] == top1 A[i] A i top1 {
				System.out.println(top2);
			} System.out.println(top2) System.out.println System.out System System.out top2 {
				System.out.println(top1);
			} System.out.println(top1) System.out.println System.out System System.out top1 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 top1 = 0;
		int top2 = 0;
		for (int i = 0; i < N; i++) {
			A[i] = sc.nextInt();
			if (A[i] > top1) {
				top2 = top1;
				top1 = A[i];
			} else if (A[i] > top2) {
				top2 = A[i];
			}
		}
		sc.close();

		for (int i = 0; i < N; i++) {
			if (A[i] == top1) {
				System.out.println(top2);
			} else {
				System.out.println(top1);
			}
		}
	}
} 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 top1 = 0;
		int top2 = 0;
		for (int i = 0; i < N; i++) {
			A[i] = sc.nextInt();
			if (A[i] > top1) {
				top2 = top1;
				top1 = A[i];
			} else if (A[i] > top2) {
				top2 = A[i];
			}
		}
		sc.close();

		for (int i = 0; i < N; i++) {
			if (A[i] == top1) {
				System.out.println(top2);
			} else {
				System.out.println(top1);
			}
		}
	}
} Main
import 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 top1 = 0;
		int top2 = 0;
		for (int i = 0; i < N; i++) {
			A[i] = sc.nextInt();
			if (A[i] > top1) {
				top2 = top1;
				top1 = A[i];
			} else if (A[i] > top2) {
				top2 = A[i];
			}
		}
		sc.close();

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