import java.util.*;
class Main {
	static Scanner sc = new Scanner(System.in);
	public static void main(String[] args) {
		int N = sc.nextInt(),A[] = new int[N],C[] = new int[N],i;
		for(i=0;i<N;i++) {
			A[i]=sc.nextInt();
			C[i]=A[i];
		}
		Arrays.sort(C);
		for(i=0;i<N;i++) System.out.println(A[i]==C[N-1]?C[N-2]:C[N-1]);
	}
} import java.util.*; util.* java class Main {
	static Scanner sc = new Scanner(System.in);
	public static void main(String[] args) {
		int N = sc.nextInt(),A[] = new int[N],C[] = new int[N],i;
		for(i=0;i<N;i++) {
			A[i]=sc.nextInt();
			C[i]=A[i];
		}
		Arrays.sort(C);
		for(i=0;i<N;i++) System.out.println(A[i]==C[N-1]?C[N-2]:C[N-1]);
	}
} Main static Scanner sc = new Scanner(System.in); sc new Scanner(System.in) public static void main(String[] args) {
		int N = sc.nextInt(),A[] = new int[N],C[] = new int[N],i;
		for(i=0;i<N;i++) {
			A[i]=sc.nextInt();
			C[i]=A[i];
		}
		Arrays.sort(C);
		for(i=0;i<N;i++) System.out.println(A[i]==C[N-1]?C[N-2]:C[N-1]);
	} main {
		int N = sc.nextInt(),A[] = new int[N],C[] = new int[N],i;
		for(i=0;i<N;i++) {
			A[i]=sc.nextInt();
			C[i]=A[i];
		}
		Arrays.sort(C);
		for(i=0;i<N;i++) System.out.println(A[i]==C[N-1]?C[N-2]:C[N-1]);
	} int N = sc.nextInt() N sc.nextInt() sc.nextInt sc A[] = new int[N] A new int[N] N C[] = new int[N] C new int[N] N i; i for(i=0;i<N;i++) {
			A[i]=sc.nextInt();
			C[i]=A[i];
		} i=0; i=0 i 0 i<N i N i++ i++ i {
			A[i]=sc.nextInt();
			C[i]=A[i];
		} {
			A[i]=sc.nextInt();
			C[i]=A[i];
		} A[i]=sc.nextInt() A[i] A i sc.nextInt() sc.nextInt sc C[i]=A[i] C[i] C i A[i] A i Arrays.sort(C) Arrays.sort Arrays C for(i=0;i<N;i++) System.out.println(A[i]==C[N-1]?C[N-2]:C[N-1]); i=0; i=0 i 0 i<N i N i++ i++ i System.out.println(A[i]==C[N-1]?C[N-2]:C[N-1]); System.out.println(A[i]==C[N-1]?C[N-2]:C[N-1]) System.out.println System.out System System.out A[i]==C[N-1]?C[N-2]:C[N-1] A[i]==C[N-1] A[i] A i C[N-1] C N-1 N 1 C[N-2] C N-2 N 2 C[N-1] C N-1 N 1 String[] args args
import java.util.*;
class Main {
	static Scanner sc = new Scanner(System.in);
	public static void main(String[] args) {
		int N = sc.nextInt(),A[] = new int[N],C[] = new int[N],i;
		for(i=0;i<N;i++) {
			A[i]=sc.nextInt();
			C[i]=A[i];
		}
		Arrays.sort(C);
		for(i=0;i<N;i++) System.out.println(A[i]==C[N-1]?C[N-2]:C[N-1]);
	}
}