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

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int maxPotision = 0;
		int maxValue = 0;
		int secondValue = 0;
		boolean maxDup = false;
		for (int i = 0; i < N; i++) {
			int tmp = sc.nextInt();
			if (tmp == maxValue) {
				maxDup = true;
			} else if (tmp > maxValue) {
				secondValue = maxValue;
				maxValue = tmp;
				maxPotision = i;
				maxDup = false;
			} else if (tmp > secondValue) {
				secondValue = tmp;
			}
		}
		if (maxDup) {
			for (int i = 0; i < N; i++) {
				System.out.println(maxValue);
			}
		} else {
			for (int i = 0; i < N; i++) {
				if (i == maxPotision) {
					System.out.println(secondValue);
				} else {
					System.out.println(maxValue);
				}
			}
		}
	}
} import java.util.Arrays; Arrays java.util import java.util.Scanner; Scanner java.util public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int maxPotision = 0;
		int maxValue = 0;
		int secondValue = 0;
		boolean maxDup = false;
		for (int i = 0; i < N; i++) {
			int tmp = sc.nextInt();
			if (tmp == maxValue) {
				maxDup = true;
			} else if (tmp > maxValue) {
				secondValue = maxValue;
				maxValue = tmp;
				maxPotision = i;
				maxDup = false;
			} else if (tmp > secondValue) {
				secondValue = tmp;
			}
		}
		if (maxDup) {
			for (int i = 0; i < N; i++) {
				System.out.println(maxValue);
			}
		} else {
			for (int i = 0; i < N; i++) {
				if (i == maxPotision) {
					System.out.println(secondValue);
				} else {
					System.out.println(maxValue);
				}
			}
		}
	}
} Main public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int maxPotision = 0;
		int maxValue = 0;
		int secondValue = 0;
		boolean maxDup = false;
		for (int i = 0; i < N; i++) {
			int tmp = sc.nextInt();
			if (tmp == maxValue) {
				maxDup = true;
			} else if (tmp > maxValue) {
				secondValue = maxValue;
				maxValue = tmp;
				maxPotision = i;
				maxDup = false;
			} else if (tmp > secondValue) {
				secondValue = tmp;
			}
		}
		if (maxDup) {
			for (int i = 0; i < N; i++) {
				System.out.println(maxValue);
			}
		} else {
			for (int i = 0; i < N; i++) {
				if (i == maxPotision) {
					System.out.println(secondValue);
				} else {
					System.out.println(maxValue);
				}
			}
		}
	} main {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int maxPotision = 0;
		int maxValue = 0;
		int secondValue = 0;
		boolean maxDup = false;
		for (int i = 0; i < N; i++) {
			int tmp = sc.nextInt();
			if (tmp == maxValue) {
				maxDup = true;
			} else if (tmp > maxValue) {
				secondValue = maxValue;
				maxValue = tmp;
				maxPotision = i;
				maxDup = false;
			} else if (tmp > secondValue) {
				secondValue = tmp;
			}
		}
		if (maxDup) {
			for (int i = 0; i < N; i++) {
				System.out.println(maxValue);
			}
		} else {
			for (int i = 0; i < N; i++) {
				if (i == maxPotision) {
					System.out.println(secondValue);
				} else {
					System.out.println(maxValue);
				}
			}
		}
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int N = sc.nextInt(); N sc.nextInt() sc.nextInt sc int maxPotision = 0; maxPotision 0 int maxValue = 0; maxValue 0 int secondValue = 0; secondValue 0 boolean maxDup = false; maxDup false for (int i = 0; i < N; i++) {
			int tmp = sc.nextInt();
			if (tmp == maxValue) {
				maxDup = true;
			} else if (tmp > maxValue) {
				secondValue = maxValue;
				maxValue = tmp;
				maxPotision = i;
				maxDup = false;
			} else if (tmp > secondValue) {
				secondValue = tmp;
			}
		} int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
			int tmp = sc.nextInt();
			if (tmp == maxValue) {
				maxDup = true;
			} else if (tmp > maxValue) {
				secondValue = maxValue;
				maxValue = tmp;
				maxPotision = i;
				maxDup = false;
			} else if (tmp > secondValue) {
				secondValue = tmp;
			}
		} {
			int tmp = sc.nextInt();
			if (tmp == maxValue) {
				maxDup = true;
			} else if (tmp > maxValue) {
				secondValue = maxValue;
				maxValue = tmp;
				maxPotision = i;
				maxDup = false;
			} else if (tmp > secondValue) {
				secondValue = tmp;
			}
		} int tmp = sc.nextInt(); tmp sc.nextInt() sc.nextInt sc if (tmp == maxValue) {
				maxDup = true;
			} else if (tmp > maxValue) {
				secondValue = maxValue;
				maxValue = tmp;
				maxPotision = i;
				maxDup = false;
			} else if (tmp > secondValue) {
				secondValue = tmp;
			} tmp == maxValue tmp maxValue {
				maxDup = true;
			} maxDup = true maxDup true if (tmp > maxValue) {
				secondValue = maxValue;
				maxValue = tmp;
				maxPotision = i;
				maxDup = false;
			} else if (tmp > secondValue) {
				secondValue = tmp;
			} tmp > maxValue tmp maxValue {
				secondValue = maxValue;
				maxValue = tmp;
				maxPotision = i;
				maxDup = false;
			} secondValue = maxValue secondValue maxValue maxValue = tmp maxValue tmp maxPotision = i maxPotision i maxDup = false maxDup false if (tmp > secondValue) {
				secondValue = tmp;
			} tmp > secondValue tmp secondValue {
				secondValue = tmp;
			} secondValue = tmp secondValue tmp if (maxDup) {
			for (int i = 0; i < N; i++) {
				System.out.println(maxValue);
			}
		} else {
			for (int i = 0; i < N; i++) {
				if (i == maxPotision) {
					System.out.println(secondValue);
				} else {
					System.out.println(maxValue);
				}
			}
		} maxDup {
			for (int i = 0; i < N; i++) {
				System.out.println(maxValue);
			}
		} for (int i = 0; i < N; i++) {
				System.out.println(maxValue);
			} int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
				System.out.println(maxValue);
			} {
				System.out.println(maxValue);
			} System.out.println(maxValue) System.out.println System.out System System.out maxValue {
			for (int i = 0; i < N; i++) {
				if (i == maxPotision) {
					System.out.println(secondValue);
				} else {
					System.out.println(maxValue);
				}
			}
		} for (int i = 0; i < N; i++) {
				if (i == maxPotision) {
					System.out.println(secondValue);
				} else {
					System.out.println(maxValue);
				}
			} int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
				if (i == maxPotision) {
					System.out.println(secondValue);
				} else {
					System.out.println(maxValue);
				}
			} {
				if (i == maxPotision) {
					System.out.println(secondValue);
				} else {
					System.out.println(maxValue);
				}
			} if (i == maxPotision) {
					System.out.println(secondValue);
				} else {
					System.out.println(maxValue);
				} i == maxPotision i maxPotision {
					System.out.println(secondValue);
				} System.out.println(secondValue) System.out.println System.out System System.out secondValue {
					System.out.println(maxValue);
				} System.out.println(maxValue) System.out.println System.out System System.out maxValue String[] args args public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int maxPotision = 0;
		int maxValue = 0;
		int secondValue = 0;
		boolean maxDup = false;
		for (int i = 0; i < N; i++) {
			int tmp = sc.nextInt();
			if (tmp == maxValue) {
				maxDup = true;
			} else if (tmp > maxValue) {
				secondValue = maxValue;
				maxValue = tmp;
				maxPotision = i;
				maxDup = false;
			} else if (tmp > secondValue) {
				secondValue = tmp;
			}
		}
		if (maxDup) {
			for (int i = 0; i < N; i++) {
				System.out.println(maxValue);
			}
		} else {
			for (int i = 0; i < N; i++) {
				if (i == maxPotision) {
					System.out.println(secondValue);
				} else {
					System.out.println(maxValue);
				}
			}
		}
	}
} public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int maxPotision = 0;
		int maxValue = 0;
		int secondValue = 0;
		boolean maxDup = false;
		for (int i = 0; i < N; i++) {
			int tmp = sc.nextInt();
			if (tmp == maxValue) {
				maxDup = true;
			} else if (tmp > maxValue) {
				secondValue = maxValue;
				maxValue = tmp;
				maxPotision = i;
				maxDup = false;
			} else if (tmp > secondValue) {
				secondValue = tmp;
			}
		}
		if (maxDup) {
			for (int i = 0; i < N; i++) {
				System.out.println(maxValue);
			}
		} else {
			for (int i = 0; i < N; i++) {
				if (i == maxPotision) {
					System.out.println(secondValue);
				} else {
					System.out.println(maxValue);
				}
			}
		}
	}
} Main
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int maxPotision = 0;
		int maxValue = 0;
		int secondValue = 0;
		boolean maxDup = false;
		for (int i = 0; i < N; i++) {
			int tmp = sc.nextInt();
			if (tmp == maxValue) {
				maxDup = true;
			} else if (tmp > maxValue) {
				secondValue = maxValue;
				maxValue = tmp;
				maxPotision = i;
				maxDup = false;
			} else if (tmp > secondValue) {
				secondValue = tmp;
			}
		}
		if (maxDup) {
			for (int i = 0; i < N; i++) {
				System.out.println(maxValue);
			}
		} else {
			for (int i = 0; i < N; i++) {
				if (i == maxPotision) {
					System.out.println(secondValue);
				} else {
					System.out.println(maxValue);
				}
			}
		}
	}
}