import java.util.ArrayList;
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 = Integer.parseInt(sc.next());
		ArrayList<Integer> A = new ArrayList<Integer>();
		ArrayList<Integer> B = new ArrayList<Integer>();
		for(int i = 0; i < N; i++) {
			A.add(Integer.parseInt(sc.next()));
			B.add(A.get(i));
		}
		sc.close();
		Collections.sort(B);
		int max = B.get(N - 1);
		int count = 0;
		for(int i = 0; i < N; i++) {
			if(max == A.get(i)) {
				count++;
			}
		}
		for(int i = 0; i < N; i++) {
			if(count < 2) {
				if(max == A.get(i)) {
					System.out.println(B.get(N - 1 - count));
				}else {
					System.out.println(max);
				}
			}else {
				System.out.println(max);
			}
		}
	}

} import java.util.ArrayList; ArrayList 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 = Integer.parseInt(sc.next());
		ArrayList<Integer> A = new ArrayList<Integer>();
		ArrayList<Integer> B = new ArrayList<Integer>();
		for(int i = 0; i < N; i++) {
			A.add(Integer.parseInt(sc.next()));
			B.add(A.get(i));
		}
		sc.close();
		Collections.sort(B);
		int max = B.get(N - 1);
		int count = 0;
		for(int i = 0; i < N; i++) {
			if(max == A.get(i)) {
				count++;
			}
		}
		for(int i = 0; i < N; i++) {
			if(count < 2) {
				if(max == A.get(i)) {
					System.out.println(B.get(N - 1 - count));
				}else {
					System.out.println(max);
				}
			}else {
				System.out.println(max);
			}
		}
	}

} Main public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = Integer.parseInt(sc.next());
		ArrayList<Integer> A = new ArrayList<Integer>();
		ArrayList<Integer> B = new ArrayList<Integer>();
		for(int i = 0; i < N; i++) {
			A.add(Integer.parseInt(sc.next()));
			B.add(A.get(i));
		}
		sc.close();
		Collections.sort(B);
		int max = B.get(N - 1);
		int count = 0;
		for(int i = 0; i < N; i++) {
			if(max == A.get(i)) {
				count++;
			}
		}
		for(int i = 0; i < N; i++) {
			if(count < 2) {
				if(max == A.get(i)) {
					System.out.println(B.get(N - 1 - count));
				}else {
					System.out.println(max);
				}
			}else {
				System.out.println(max);
			}
		}
	} main {
		Scanner sc = new Scanner(System.in);
		int N = Integer.parseInt(sc.next());
		ArrayList<Integer> A = new ArrayList<Integer>();
		ArrayList<Integer> B = new ArrayList<Integer>();
		for(int i = 0; i < N; i++) {
			A.add(Integer.parseInt(sc.next()));
			B.add(A.get(i));
		}
		sc.close();
		Collections.sort(B);
		int max = B.get(N - 1);
		int count = 0;
		for(int i = 0; i < N; i++) {
			if(max == A.get(i)) {
				count++;
			}
		}
		for(int i = 0; i < N; i++) {
			if(count < 2) {
				if(max == A.get(i)) {
					System.out.println(B.get(N - 1 - count));
				}else {
					System.out.println(max);
				}
			}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 ArrayList<Integer> A = new ArrayList<Integer>(); A new ArrayList<Integer>() ArrayList<Integer> B = new ArrayList<Integer>(); B new ArrayList<Integer>() for(int i = 0; i < N; i++) {
			A.add(Integer.parseInt(sc.next()));
			B.add(A.get(i));
		} int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
			A.add(Integer.parseInt(sc.next()));
			B.add(A.get(i));
		} {
			A.add(Integer.parseInt(sc.next()));
			B.add(A.get(i));
		} A.add(Integer.parseInt(sc.next())) A.add A Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc B.add(A.get(i)) B.add B A.get(i) A.get A i sc.close() sc.close sc Collections.sort(B) Collections.sort Collections B int max = B.get(N - 1); max B.get(N - 1) B.get B N - 1 N 1 int count = 0; count 0 for(int i = 0; i < N; i++) {
			if(max == A.get(i)) {
				count++;
			}
		} int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
			if(max == A.get(i)) {
				count++;
			}
		} {
			if(max == A.get(i)) {
				count++;
			}
		} if(max == A.get(i)) {
				count++;
			} max == A.get(i) max A.get(i) A.get A i {
				count++;
			} count++ count for(int i = 0; i < N; i++) {
			if(count < 2) {
				if(max == A.get(i)) {
					System.out.println(B.get(N - 1 - count));
				}else {
					System.out.println(max);
				}
			}else {
				System.out.println(max);
			}
		} int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
			if(count < 2) {
				if(max == A.get(i)) {
					System.out.println(B.get(N - 1 - count));
				}else {
					System.out.println(max);
				}
			}else {
				System.out.println(max);
			}
		} {
			if(count < 2) {
				if(max == A.get(i)) {
					System.out.println(B.get(N - 1 - count));
				}else {
					System.out.println(max);
				}
			}else {
				System.out.println(max);
			}
		} if(count < 2) {
				if(max == A.get(i)) {
					System.out.println(B.get(N - 1 - count));
				}else {
					System.out.println(max);
				}
			}else {
				System.out.println(max);
			} count < 2 count 2 {
				if(max == A.get(i)) {
					System.out.println(B.get(N - 1 - count));
				}else {
					System.out.println(max);
				}
			} if(max == A.get(i)) {
					System.out.println(B.get(N - 1 - count));
				}else {
					System.out.println(max);
				} max == A.get(i) max A.get(i) A.get A i {
					System.out.println(B.get(N - 1 - count));
				} System.out.println(B.get(N - 1 - count)) System.out.println System.out System System.out B.get(N - 1 - count) B.get B N - 1 - count N - 1 - count N 1 count {
					System.out.println(max);
				} System.out.println(max) System.out.println System.out System System.out max {
				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());
		ArrayList<Integer> A = new ArrayList<Integer>();
		ArrayList<Integer> B = new ArrayList<Integer>();
		for(int i = 0; i < N; i++) {
			A.add(Integer.parseInt(sc.next()));
			B.add(A.get(i));
		}
		sc.close();
		Collections.sort(B);
		int max = B.get(N - 1);
		int count = 0;
		for(int i = 0; i < N; i++) {
			if(max == A.get(i)) {
				count++;
			}
		}
		for(int i = 0; i < N; i++) {
			if(count < 2) {
				if(max == A.get(i)) {
					System.out.println(B.get(N - 1 - count));
				}else {
					System.out.println(max);
				}
			}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());
		ArrayList<Integer> A = new ArrayList<Integer>();
		ArrayList<Integer> B = new ArrayList<Integer>();
		for(int i = 0; i < N; i++) {
			A.add(Integer.parseInt(sc.next()));
			B.add(A.get(i));
		}
		sc.close();
		Collections.sort(B);
		int max = B.get(N - 1);
		int count = 0;
		for(int i = 0; i < N; i++) {
			if(max == A.get(i)) {
				count++;
			}
		}
		for(int i = 0; i < N; i++) {
			if(count < 2) {
				if(max == A.get(i)) {
					System.out.println(B.get(N - 1 - count));
				}else {
					System.out.println(max);
				}
			}else {
				System.out.println(max);
			}
		}
	}

} Main
import java.util.ArrayList;
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 = Integer.parseInt(sc.next());
		ArrayList<Integer> A = new ArrayList<Integer>();
		ArrayList<Integer> B = new ArrayList<Integer>();
		for(int i = 0; i < N; i++) {
			A.add(Integer.parseInt(sc.next()));
			B.add(A.get(i));
		}
		sc.close();
		Collections.sort(B);
		int max = B.get(N - 1);
		int count = 0;
		for(int i = 0; i < N; i++) {
			if(max == A.get(i)) {
				count++;
			}
		}
		for(int i = 0; i < N; i++) {
			if(count < 2) {
				if(max == A.get(i)) {
					System.out.println(B.get(N - 1 - count));
				}else {
					System.out.println(max);
				}
			}else {
				System.out.println(max);
			}
		}
	}

}