import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		final int N = Integer.parseInt(sc.next());
		int[] a = new int[N];
		int first = 0;
		int second = 0;
		int loc = 0;
		for (int i = 0; i < N; i++) {
			int k = Integer.parseInt(sc.next());
			if(second <= k) {
				if(first <= k) {
					second = first;
					first = k;
					loc = i;
				} else {
					second = k;
				}
			}
		}
		for (int j = 0; j < N; j++) {
			if(j == loc) {
				System.out.println(second);
			} else {
				System.out.println(first);
			}
		}
	}

} import java.util.Scanner; Scanner java.util public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		final int N = Integer.parseInt(sc.next());
		int[] a = new int[N];
		int first = 0;
		int second = 0;
		int loc = 0;
		for (int i = 0; i < N; i++) {
			int k = Integer.parseInt(sc.next());
			if(second <= k) {
				if(first <= k) {
					second = first;
					first = k;
					loc = i;
				} else {
					second = k;
				}
			}
		}
		for (int j = 0; j < N; j++) {
			if(j == loc) {
				System.out.println(second);
			} else {
				System.out.println(first);
			}
		}
	}

} Main public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		final int N = Integer.parseInt(sc.next());
		int[] a = new int[N];
		int first = 0;
		int second = 0;
		int loc = 0;
		for (int i = 0; i < N; i++) {
			int k = Integer.parseInt(sc.next());
			if(second <= k) {
				if(first <= k) {
					second = first;
					first = k;
					loc = i;
				} else {
					second = k;
				}
			}
		}
		for (int j = 0; j < N; j++) {
			if(j == loc) {
				System.out.println(second);
			} else {
				System.out.println(first);
			}
		}
	} main {
		Scanner sc = new Scanner(System.in);
		final int N = Integer.parseInt(sc.next());
		int[] a = new int[N];
		int first = 0;
		int second = 0;
		int loc = 0;
		for (int i = 0; i < N; i++) {
			int k = Integer.parseInt(sc.next());
			if(second <= k) {
				if(first <= k) {
					second = first;
					first = k;
					loc = i;
				} else {
					second = k;
				}
			}
		}
		for (int j = 0; j < N; j++) {
			if(j == loc) {
				System.out.println(second);
			} else {
				System.out.println(first);
			}
		}
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) final int N = Integer.parseInt(sc.next()); N Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc int[] a = new int[N]; a new int[N] N int first = 0; first 0 int second = 0; second 0 int loc = 0; loc 0 for (int i = 0; i < N; i++) {
			int k = Integer.parseInt(sc.next());
			if(second <= k) {
				if(first <= k) {
					second = first;
					first = k;
					loc = i;
				} else {
					second = k;
				}
			}
		} int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
			int k = Integer.parseInt(sc.next());
			if(second <= k) {
				if(first <= k) {
					second = first;
					first = k;
					loc = i;
				} else {
					second = k;
				}
			}
		} {
			int k = Integer.parseInt(sc.next());
			if(second <= k) {
				if(first <= k) {
					second = first;
					first = k;
					loc = i;
				} else {
					second = k;
				}
			}
		} int k = Integer.parseInt(sc.next()); k Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc if(second <= k) {
				if(first <= k) {
					second = first;
					first = k;
					loc = i;
				} else {
					second = k;
				}
			} second <= k second k {
				if(first <= k) {
					second = first;
					first = k;
					loc = i;
				} else {
					second = k;
				}
			} if(first <= k) {
					second = first;
					first = k;
					loc = i;
				} else {
					second = k;
				} first <= k first k {
					second = first;
					first = k;
					loc = i;
				} second = first second first first = k first k loc = i loc i {
					second = k;
				} second = k second k for (int j = 0; j < N; j++) {
			if(j == loc) {
				System.out.println(second);
			} else {
				System.out.println(first);
			}
		} int j = 0; int j = 0; j 0 j < N j N j++ j++ j {
			if(j == loc) {
				System.out.println(second);
			} else {
				System.out.println(first);
			}
		} {
			if(j == loc) {
				System.out.println(second);
			} else {
				System.out.println(first);
			}
		} if(j == loc) {
				System.out.println(second);
			} else {
				System.out.println(first);
			} j == loc j loc {
				System.out.println(second);
			} System.out.println(second) System.out.println System.out System System.out second {
				System.out.println(first);
			} System.out.println(first) System.out.println System.out System System.out first String[] args args public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		final int N = Integer.parseInt(sc.next());
		int[] a = new int[N];
		int first = 0;
		int second = 0;
		int loc = 0;
		for (int i = 0; i < N; i++) {
			int k = Integer.parseInt(sc.next());
			if(second <= k) {
				if(first <= k) {
					second = first;
					first = k;
					loc = i;
				} else {
					second = k;
				}
			}
		}
		for (int j = 0; j < N; j++) {
			if(j == loc) {
				System.out.println(second);
			} else {
				System.out.println(first);
			}
		}
	}

} public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		final int N = Integer.parseInt(sc.next());
		int[] a = new int[N];
		int first = 0;
		int second = 0;
		int loc = 0;
		for (int i = 0; i < N; i++) {
			int k = Integer.parseInt(sc.next());
			if(second <= k) {
				if(first <= k) {
					second = first;
					first = k;
					loc = i;
				} else {
					second = k;
				}
			}
		}
		for (int j = 0; j < N; j++) {
			if(j == loc) {
				System.out.println(second);
			} else {
				System.out.println(first);
			}
		}
	}

} Main
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		final int N = Integer.parseInt(sc.next());
		int[] a = new int[N];
		int first = 0;
		int second = 0;
		int loc = 0;
		for (int i = 0; i < N; i++) {
			int k = Integer.parseInt(sc.next());
			if(second <= k) {
				if(first <= k) {
					second = first;
					first = k;
					loc = i;
				} else {
					second = k;
				}
			}
		}
		for (int j = 0; j < N; j++) {
			if(j == loc) {
				System.out.println(second);
			} else {
				System.out.println(first);
			}
		}
	}

}
