import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int N = scan.nextInt();
		int[] A = new int[N];
		
		int largest = 0;
		int largestI = 0;
		int second = 0;
		int secondI = 0;
		
		for(int i=0; i<N; i++) {
			A[i] = scan.nextInt();
			if(largest < A[i]) {
				largest = A[i];
				largestI = i;
			} else if(second < A[i]) {
				second = A[i];
				secondI = i;
			}
		}
		scan.close();

		for(int i=0; i<A.length; i++) {
			if(i==largestI) {
				System.out.println(A[secondI]);
			} else {
				System.out.println(A[largestI]);
			}
		}
		
	}

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

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int N = scan.nextInt();
		int[] A = new int[N];
		
		int largest = 0;
		int largestI = 0;
		int second = 0;
		int secondI = 0;
		
		for(int i=0; i<N; i++) {
			A[i] = scan.nextInt();
			if(largest < A[i]) {
				largest = A[i];
				largestI = i;
			} else if(second < A[i]) {
				second = A[i];
				secondI = i;
			}
		}
		scan.close();

		for(int i=0; i<A.length; i++) {
			if(i==largestI) {
				System.out.println(A[secondI]);
			} else {
				System.out.println(A[largestI]);
			}
		}
		
	}

} Main public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int N = scan.nextInt();
		int[] A = new int[N];
		
		int largest = 0;
		int largestI = 0;
		int second = 0;
		int secondI = 0;
		
		for(int i=0; i<N; i++) {
			A[i] = scan.nextInt();
			if(largest < A[i]) {
				largest = A[i];
				largestI = i;
			} else if(second < A[i]) {
				second = A[i];
				secondI = i;
			}
		}
		scan.close();

		for(int i=0; i<A.length; i++) {
			if(i==largestI) {
				System.out.println(A[secondI]);
			} else {
				System.out.println(A[largestI]);
			}
		}
		
	} main {
		Scanner scan = new Scanner(System.in);
		int N = scan.nextInt();
		int[] A = new int[N];
		
		int largest = 0;
		int largestI = 0;
		int second = 0;
		int secondI = 0;
		
		for(int i=0; i<N; i++) {
			A[i] = scan.nextInt();
			if(largest < A[i]) {
				largest = A[i];
				largestI = i;
			} else if(second < A[i]) {
				second = A[i];
				secondI = i;
			}
		}
		scan.close();

		for(int i=0; i<A.length; i++) {
			if(i==largestI) {
				System.out.println(A[secondI]);
			} else {
				System.out.println(A[largestI]);
			}
		}
		
	} Scanner scan = new Scanner(System.in); scan new Scanner(System.in) int N = scan.nextInt(); N scan.nextInt() scan.nextInt scan int[] A = new int[N]; A new int[N] N int largest = 0; largest 0 int largestI = 0; largestI 0 int second = 0; second 0 int secondI = 0; secondI 0 for(int i=0; i<N; i++) {
			A[i] = scan.nextInt();
			if(largest < A[i]) {
				largest = A[i];
				largestI = i;
			} else if(second < A[i]) {
				second = A[i];
				secondI = i;
			}
		} int i=0; int i=0; i 0 i<N i N i++ i++ i {
			A[i] = scan.nextInt();
			if(largest < A[i]) {
				largest = A[i];
				largestI = i;
			} else if(second < A[i]) {
				second = A[i];
				secondI = i;
			}
		} {
			A[i] = scan.nextInt();
			if(largest < A[i]) {
				largest = A[i];
				largestI = i;
			} else if(second < A[i]) {
				second = A[i];
				secondI = i;
			}
		} A[i] = scan.nextInt() A[i] A i scan.nextInt() scan.nextInt scan if(largest < A[i]) {
				largest = A[i];
				largestI = i;
			} else if(second < A[i]) {
				second = A[i];
				secondI = i;
			} largest < A[i] largest A[i] A i {
				largest = A[i];
				largestI = i;
			} largest = A[i] largest A[i] A i largestI = i largestI i if(second < A[i]) {
				second = A[i];
				secondI = i;
			} second < A[i] second A[i] A i {
				second = A[i];
				secondI = i;
			} second = A[i] second A[i] A i secondI = i secondI i scan.close() scan.close scan for(int i=0; i<A.length; i++) {
			if(i==largestI) {
				System.out.println(A[secondI]);
			} else {
				System.out.println(A[largestI]);
			}
		} int i=0; int i=0; i 0 i<A.length i A.length A A.length i++ i++ i {
			if(i==largestI) {
				System.out.println(A[secondI]);
			} else {
				System.out.println(A[largestI]);
			}
		} {
			if(i==largestI) {
				System.out.println(A[secondI]);
			} else {
				System.out.println(A[largestI]);
			}
		} if(i==largestI) {
				System.out.println(A[secondI]);
			} else {
				System.out.println(A[largestI]);
			} i==largestI i largestI {
				System.out.println(A[secondI]);
			} System.out.println(A[secondI]) System.out.println System.out System System.out A[secondI] A secondI {
				System.out.println(A[largestI]);
			} System.out.println(A[largestI]) System.out.println System.out System System.out A[largestI] A largestI String[] args args public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int N = scan.nextInt();
		int[] A = new int[N];
		
		int largest = 0;
		int largestI = 0;
		int second = 0;
		int secondI = 0;
		
		for(int i=0; i<N; i++) {
			A[i] = scan.nextInt();
			if(largest < A[i]) {
				largest = A[i];
				largestI = i;
			} else if(second < A[i]) {
				second = A[i];
				secondI = i;
			}
		}
		scan.close();

		for(int i=0; i<A.length; i++) {
			if(i==largestI) {
				System.out.println(A[secondI]);
			} else {
				System.out.println(A[largestI]);
			}
		}
		
	}

} public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int N = scan.nextInt();
		int[] A = new int[N];
		
		int largest = 0;
		int largestI = 0;
		int second = 0;
		int secondI = 0;
		
		for(int i=0; i<N; i++) {
			A[i] = scan.nextInt();
			if(largest < A[i]) {
				largest = A[i];
				largestI = i;
			} else if(second < A[i]) {
				second = A[i];
				secondI = i;
			}
		}
		scan.close();

		for(int i=0; i<A.length; i++) {
			if(i==largestI) {
				System.out.println(A[secondI]);
			} else {
				System.out.println(A[largestI]);
			}
		}
		
	}

} Main
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int N = scan.nextInt();
		int[] A = new int[N];
		
		int largest = 0;
		int largestI = 0;
		int second = 0;
		int secondI = 0;
		
		for(int i=0; i<N; i++) {
			A[i] = scan.nextInt();
			if(largest < A[i]) {
				largest = A[i];
				largestI = i;
			} else if(second < A[i]) {
				second = A[i];
				secondI = i;
			}
		}
		scan.close();

		for(int i=0; i<A.length; i++) {
			if(i==largestI) {
				System.out.println(A[secondI]);
			} else {
				System.out.println(A[largestI]);
			}
		}
		
	}

}