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 max = 0;
		int max_i = 0;
		int next_max = 0;
		for(int i = 0; i < N; i++) {
			A[i] = sc.nextInt();
			if(A[i] >= max) {
				next_max = max;
				max = A[i];
				max_i = i;
			} else if(A[i] > next_max) {
				next_max = A[i];
			}
		}
		
		for(int i = 0; i < N; i++) {
			if(i != max_i) {
				System.out.println(max);
			} else {
				System.out.println(next_max);
			}
		}
	}
} 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 max = 0;
		int max_i = 0;
		int next_max = 0;
		for(int i = 0; i < N; i++) {
			A[i] = sc.nextInt();
			if(A[i] >= max) {
				next_max = max;
				max = A[i];
				max_i = i;
			} else if(A[i] > next_max) {
				next_max = A[i];
			}
		}
		
		for(int i = 0; i < N; i++) {
			if(i != max_i) {
				System.out.println(max);
			} else {
				System.out.println(next_max);
			}
		}
	}
} Main public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int A[] = new int[N];
		int max = 0;
		int max_i = 0;
		int next_max = 0;
		for(int i = 0; i < N; i++) {
			A[i] = sc.nextInt();
			if(A[i] >= max) {
				next_max = max;
				max = A[i];
				max_i = i;
			} else if(A[i] > next_max) {
				next_max = A[i];
			}
		}
		
		for(int i = 0; i < N; i++) {
			if(i != max_i) {
				System.out.println(max);
			} else {
				System.out.println(next_max);
			}
		}
	} main {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int A[] = new int[N];
		int max = 0;
		int max_i = 0;
		int next_max = 0;
		for(int i = 0; i < N; i++) {
			A[i] = sc.nextInt();
			if(A[i] >= max) {
				next_max = max;
				max = A[i];
				max_i = i;
			} else if(A[i] > next_max) {
				next_max = A[i];
			}
		}
		
		for(int i = 0; i < N; i++) {
			if(i != max_i) {
				System.out.println(max);
			} else {
				System.out.println(next_max);
			}
		}
	} 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 max = 0; max 0 int max_i = 0; max_i 0 int next_max = 0; next_max 0 for(int i = 0; i < N; i++) {
			A[i] = sc.nextInt();
			if(A[i] >= max) {
				next_max = max;
				max = A[i];
				max_i = i;
			} else if(A[i] > next_max) {
				next_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) {
				next_max = max;
				max = A[i];
				max_i = i;
			} else if(A[i] > next_max) {
				next_max = A[i];
			}
		} {
			A[i] = sc.nextInt();
			if(A[i] >= max) {
				next_max = max;
				max = A[i];
				max_i = i;
			} else if(A[i] > next_max) {
				next_max = A[i];
			}
		} A[i] = sc.nextInt() A[i] A i sc.nextInt() sc.nextInt sc if(A[i] >= max) {
				next_max = max;
				max = A[i];
				max_i = i;
			} else if(A[i] > next_max) {
				next_max = A[i];
			} A[i] >= max A[i] A i max {
				next_max = max;
				max = A[i];
				max_i = i;
			} next_max = max next_max max max = A[i] max A[i] A i max_i = i max_i i if(A[i] > next_max) {
				next_max = A[i];
			} A[i] > next_max A[i] A i next_max {
				next_max = A[i];
			} next_max = A[i] next_max A[i] A i for(int i = 0; i < N; i++) {
			if(i != max_i) {
				System.out.println(max);
			} else {
				System.out.println(next_max);
			}
		} int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
			if(i != max_i) {
				System.out.println(max);
			} else {
				System.out.println(next_max);
			}
		} {
			if(i != max_i) {
				System.out.println(max);
			} else {
				System.out.println(next_max);
			}
		} if(i != max_i) {
				System.out.println(max);
			} else {
				System.out.println(next_max);
			} i != max_i i max_i {
				System.out.println(max);
			} System.out.println(max) System.out.println System.out System System.out max {
				System.out.println(next_max);
			} System.out.println(next_max) System.out.println System.out System System.out next_max 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 max = 0;
		int max_i = 0;
		int next_max = 0;
		for(int i = 0; i < N; i++) {
			A[i] = sc.nextInt();
			if(A[i] >= max) {
				next_max = max;
				max = A[i];
				max_i = i;
			} else if(A[i] > next_max) {
				next_max = A[i];
			}
		}
		
		for(int i = 0; i < N; i++) {
			if(i != max_i) {
				System.out.println(max);
			} else {
				System.out.println(next_max);
			}
		}
	}
} 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 max = 0;
		int max_i = 0;
		int next_max = 0;
		for(int i = 0; i < N; i++) {
			A[i] = sc.nextInt();
			if(A[i] >= max) {
				next_max = max;
				max = A[i];
				max_i = i;
			} else if(A[i] > next_max) {
				next_max = A[i];
			}
		}
		
		for(int i = 0; i < N; i++) {
			if(i != max_i) {
				System.out.println(max);
			} else {
				System.out.println(next_max);
			}
		}
	}
} 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 max = 0;
		int max_i = 0;
		int next_max = 0;
		for(int i = 0; i < N; i++) {
			A[i] = sc.nextInt();
			if(A[i] >= max) {
				next_max = max;
				max = A[i];
				max_i = i;
			} else if(A[i] > next_max) {
				next_max = A[i];
			}
		}
		
		for(int i = 0; i < N; i++) {
			if(i != max_i) {
				System.out.println(max);
			} else {
				System.out.println(next_max);
			}
		}
	}
}
