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

public class Main {

	public static void main(String[] args) {


		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] array = new int[n];
		for(int i = 0; i < n; i++) {
			array[i] = sc.nextInt();
		}
		int []tmpArray = array.clone();
		Arrays.sort(array);
		if(array[n-1] == array[n-2]) {
			for(int i = 0; i < n;i++) {
				System.out.println(array[n-1]);
			}
		}else {
			int index = 0;
			for(int i = 0; i < n;i++) {
				if(tmpArray[i] == array[n-1]) {
					index = i;
				}
			}
			for(int i = 0; i < n;i++) {
				if(i != index) {
					System.out.println(array[n-1]);
				}else {
					System.out.println(array[n-2]);
				}
			}
		}
	}

} import java.util.Arrays; Arrays 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 = sc.nextInt();
		int[] array = new int[n];
		for(int i = 0; i < n; i++) {
			array[i] = sc.nextInt();
		}
		int []tmpArray = array.clone();
		Arrays.sort(array);
		if(array[n-1] == array[n-2]) {
			for(int i = 0; i < n;i++) {
				System.out.println(array[n-1]);
			}
		}else {
			int index = 0;
			for(int i = 0; i < n;i++) {
				if(tmpArray[i] == array[n-1]) {
					index = i;
				}
			}
			for(int i = 0; i < n;i++) {
				if(i != index) {
					System.out.println(array[n-1]);
				}else {
					System.out.println(array[n-2]);
				}
			}
		}
	}

} Main public static void main(String[] args) {


		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] array = new int[n];
		for(int i = 0; i < n; i++) {
			array[i] = sc.nextInt();
		}
		int []tmpArray = array.clone();
		Arrays.sort(array);
		if(array[n-1] == array[n-2]) {
			for(int i = 0; i < n;i++) {
				System.out.println(array[n-1]);
			}
		}else {
			int index = 0;
			for(int i = 0; i < n;i++) {
				if(tmpArray[i] == array[n-1]) {
					index = i;
				}
			}
			for(int i = 0; i < n;i++) {
				if(i != index) {
					System.out.println(array[n-1]);
				}else {
					System.out.println(array[n-2]);
				}
			}
		}
	} main {


		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] array = new int[n];
		for(int i = 0; i < n; i++) {
			array[i] = sc.nextInt();
		}
		int []tmpArray = array.clone();
		Arrays.sort(array);
		if(array[n-1] == array[n-2]) {
			for(int i = 0; i < n;i++) {
				System.out.println(array[n-1]);
			}
		}else {
			int index = 0;
			for(int i = 0; i < n;i++) {
				if(tmpArray[i] == array[n-1]) {
					index = i;
				}
			}
			for(int i = 0; i < n;i++) {
				if(i != index) {
					System.out.println(array[n-1]);
				}else {
					System.out.println(array[n-2]);
				}
			}
		}
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int[] array = new int[n]; array new int[n] n for(int i = 0; i < n; i++) {
			array[i] = sc.nextInt();
		} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
			array[i] = sc.nextInt();
		} {
			array[i] = sc.nextInt();
		} array[i] = sc.nextInt() array[i] array i sc.nextInt() sc.nextInt sc int []tmpArray = array.clone(); tmpArray array.clone() array.clone array Arrays.sort(array) Arrays.sort Arrays array if(array[n-1] == array[n-2]) {
			for(int i = 0; i < n;i++) {
				System.out.println(array[n-1]);
			}
		}else {
			int index = 0;
			for(int i = 0; i < n;i++) {
				if(tmpArray[i] == array[n-1]) {
					index = i;
				}
			}
			for(int i = 0; i < n;i++) {
				if(i != index) {
					System.out.println(array[n-1]);
				}else {
					System.out.println(array[n-2]);
				}
			}
		} array[n-1] == array[n-2] array[n-1] array n-1 n 1 array[n-2] array n-2 n 2 {
			for(int i = 0; i < n;i++) {
				System.out.println(array[n-1]);
			}
		} for(int i = 0; i < n;i++) {
				System.out.println(array[n-1]);
			} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
				System.out.println(array[n-1]);
			} {
				System.out.println(array[n-1]);
			} System.out.println(array[n-1]) System.out.println System.out System System.out array[n-1] array n-1 n 1 {
			int index = 0;
			for(int i = 0; i < n;i++) {
				if(tmpArray[i] == array[n-1]) {
					index = i;
				}
			}
			for(int i = 0; i < n;i++) {
				if(i != index) {
					System.out.println(array[n-1]);
				}else {
					System.out.println(array[n-2]);
				}
			}
		} int index = 0; index 0 for(int i = 0; i < n;i++) {
				if(tmpArray[i] == array[n-1]) {
					index = i;
				}
			} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
				if(tmpArray[i] == array[n-1]) {
					index = i;
				}
			} {
				if(tmpArray[i] == array[n-1]) {
					index = i;
				}
			} if(tmpArray[i] == array[n-1]) {
					index = i;
				} tmpArray[i] == array[n-1] tmpArray[i] tmpArray i array[n-1] array n-1 n 1 {
					index = i;
				} index = i index i for(int i = 0; i < n;i++) {
				if(i != index) {
					System.out.println(array[n-1]);
				}else {
					System.out.println(array[n-2]);
				}
			} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
				if(i != index) {
					System.out.println(array[n-1]);
				}else {
					System.out.println(array[n-2]);
				}
			} {
				if(i != index) {
					System.out.println(array[n-1]);
				}else {
					System.out.println(array[n-2]);
				}
			} if(i != index) {
					System.out.println(array[n-1]);
				}else {
					System.out.println(array[n-2]);
				} i != index i index {
					System.out.println(array[n-1]);
				} System.out.println(array[n-1]) System.out.println System.out System System.out array[n-1] array n-1 n 1 {
					System.out.println(array[n-2]);
				} System.out.println(array[n-2]) System.out.println System.out System System.out array[n-2] array n-2 n 2 String[] args args public class Main {

	public static void main(String[] args) {


		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] array = new int[n];
		for(int i = 0; i < n; i++) {
			array[i] = sc.nextInt();
		}
		int []tmpArray = array.clone();
		Arrays.sort(array);
		if(array[n-1] == array[n-2]) {
			for(int i = 0; i < n;i++) {
				System.out.println(array[n-1]);
			}
		}else {
			int index = 0;
			for(int i = 0; i < n;i++) {
				if(tmpArray[i] == array[n-1]) {
					index = i;
				}
			}
			for(int i = 0; i < n;i++) {
				if(i != index) {
					System.out.println(array[n-1]);
				}else {
					System.out.println(array[n-2]);
				}
			}
		}
	}

} public class Main {

	public static void main(String[] args) {


		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] array = new int[n];
		for(int i = 0; i < n; i++) {
			array[i] = sc.nextInt();
		}
		int []tmpArray = array.clone();
		Arrays.sort(array);
		if(array[n-1] == array[n-2]) {
			for(int i = 0; i < n;i++) {
				System.out.println(array[n-1]);
			}
		}else {
			int index = 0;
			for(int i = 0; i < n;i++) {
				if(tmpArray[i] == array[n-1]) {
					index = i;
				}
			}
			for(int i = 0; i < n;i++) {
				if(i != index) {
					System.out.println(array[n-1]);
				}else {
					System.out.println(array[n-2]);
				}
			}
		}
	}

} Main
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {


		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] array = new int[n];
		for(int i = 0; i < n; i++) {
			array[i] = sc.nextInt();
		}
		int []tmpArray = array.clone();
		Arrays.sort(array);
		if(array[n-1] == array[n-2]) {
			for(int i = 0; i < n;i++) {
				System.out.println(array[n-1]);
			}
		}else {
			int index = 0;
			for(int i = 0; i < n;i++) {
				if(tmpArray[i] == array[n-1]) {
					index = i;
				}
			}
			for(int i = 0; i < n;i++) {
				if(i != index) {
					System.out.println(array[n-1]);
				}else {
					System.out.println(array[n-2]);
				}
			}
		}
	}

}