import java.util.Scanner;
public class Main {
@SuppressWarnings("resource")
public static void main(String[] args) {
	Scanner sc=new Scanner(System.in);
	int N=sc.nextInt();
	int[] A=new int[N];
	int max=0;
	int secondMax=0;
	for(int i=0;i<N;i++) {
		A[i]=sc.nextInt();
		if(A[i]>max) {
			secondMax=max;
			max=A[i];
		}else if(A[i]>secondMax) {
			secondMax=A[i];
		}
	}
	for(int i=0;i<N;i++) {
		if(A[i]==max) {
			System.out.println(secondMax);
		}else {
			System.out.println(max);
		}
	}
}
} import java.util.Scanner; Scanner java.util public class Main {
@SuppressWarnings("resource")
public static void main(String[] args) {
	Scanner sc=new Scanner(System.in);
	int N=sc.nextInt();
	int[] A=new int[N];
	int max=0;
	int secondMax=0;
	for(int i=0;i<N;i++) {
		A[i]=sc.nextInt();
		if(A[i]>max) {
			secondMax=max;
			max=A[i];
		}else if(A[i]>secondMax) {
			secondMax=A[i];
		}
	}
	for(int i=0;i<N;i++) {
		if(A[i]==max) {
			System.out.println(secondMax);
		}else {
			System.out.println(max);
		}
	}
}
} Main @SuppressWarnings("resource")
public static void main(String[] args) {
	Scanner sc=new Scanner(System.in);
	int N=sc.nextInt();
	int[] A=new int[N];
	int max=0;
	int secondMax=0;
	for(int i=0;i<N;i++) {
		A[i]=sc.nextInt();
		if(A[i]>max) {
			secondMax=max;
			max=A[i];
		}else if(A[i]>secondMax) {
			secondMax=A[i];
		}
	}
	for(int i=0;i<N;i++) {
		if(A[i]==max) {
			System.out.println(secondMax);
		}else {
			System.out.println(max);
		}
	}
} main {
	Scanner sc=new Scanner(System.in);
	int N=sc.nextInt();
	int[] A=new int[N];
	int max=0;
	int secondMax=0;
	for(int i=0;i<N;i++) {
		A[i]=sc.nextInt();
		if(A[i]>max) {
			secondMax=max;
			max=A[i];
		}else if(A[i]>secondMax) {
			secondMax=A[i];
		}
	}
	for(int i=0;i<N;i++) {
		if(A[i]==max) {
			System.out.println(secondMax);
		}else {
			System.out.println(max);
		}
	}
} Scanner sc=new Scanner(System.in); sc new Scanner(System.in) int N=sc.nextInt(); N sc.nextInt() sc.nextInt sc int[] A=new int[N]; A new int[N] N int max=0; max 0 int secondMax=0; secondMax 0 for(int i=0;i<N;i++) {
		A[i]=sc.nextInt();
		if(A[i]>max) {
			secondMax=max;
			max=A[i];
		}else if(A[i]>secondMax) {
			secondMax=A[i];
		}
	} int i=0; int i=0; i 0 i<N i N i++ i++ i {
		A[i]=sc.nextInt();
		if(A[i]>max) {
			secondMax=max;
			max=A[i];
		}else if(A[i]>secondMax) {
			secondMax=A[i];
		}
	} {
		A[i]=sc.nextInt();
		if(A[i]>max) {
			secondMax=max;
			max=A[i];
		}else if(A[i]>secondMax) {
			secondMax=A[i];
		}
	} A[i]=sc.nextInt() A[i] A i sc.nextInt() sc.nextInt sc if(A[i]>max) {
			secondMax=max;
			max=A[i];
		}else if(A[i]>secondMax) {
			secondMax=A[i];
		} A[i]>max A[i] A i max {
			secondMax=max;
			max=A[i];
		} secondMax=max secondMax max max=A[i] max A[i] A i if(A[i]>secondMax) {
			secondMax=A[i];
		} A[i]>secondMax A[i] A i secondMax {
			secondMax=A[i];
		} secondMax=A[i] secondMax A[i] A i for(int i=0;i<N;i++) {
		if(A[i]==max) {
			System.out.println(secondMax);
		}else {
			System.out.println(max);
		}
	} int i=0; int i=0; i 0 i<N i N i++ i++ i {
		if(A[i]==max) {
			System.out.println(secondMax);
		}else {
			System.out.println(max);
		}
	} {
		if(A[i]==max) {
			System.out.println(secondMax);
		}else {
			System.out.println(max);
		}
	} if(A[i]==max) {
			System.out.println(secondMax);
		}else {
			System.out.println(max);
		} A[i]==max A[i] A i max {
			System.out.println(secondMax);
		} System.out.println(secondMax) System.out.println System.out System System.out secondMax {
			System.out.println(max);
		} System.out.println(max) System.out.println System.out System System.out max String[] args args public class Main {
@SuppressWarnings("resource")
public static void main(String[] args) {
	Scanner sc=new Scanner(System.in);
	int N=sc.nextInt();
	int[] A=new int[N];
	int max=0;
	int secondMax=0;
	for(int i=0;i<N;i++) {
		A[i]=sc.nextInt();
		if(A[i]>max) {
			secondMax=max;
			max=A[i];
		}else if(A[i]>secondMax) {
			secondMax=A[i];
		}
	}
	for(int i=0;i<N;i++) {
		if(A[i]==max) {
			System.out.println(secondMax);
		}else {
			System.out.println(max);
		}
	}
}
} public class Main {
@SuppressWarnings("resource")
public static void main(String[] args) {
	Scanner sc=new Scanner(System.in);
	int N=sc.nextInt();
	int[] A=new int[N];
	int max=0;
	int secondMax=0;
	for(int i=0;i<N;i++) {
		A[i]=sc.nextInt();
		if(A[i]>max) {
			secondMax=max;
			max=A[i];
		}else if(A[i]>secondMax) {
			secondMax=A[i];
		}
	}
	for(int i=0;i<N;i++) {
		if(A[i]==max) {
			System.out.println(secondMax);
		}else {
			System.out.println(max);
		}
	}
}
} Main
import java.util.Scanner;
public class Main {
@SuppressWarnings("resource")
public static void main(String[] args) {
	Scanner sc=new Scanner(System.in);
	int N=sc.nextInt();
	int[] A=new int[N];
	int max=0;
	int secondMax=0;
	for(int i=0;i<N;i++) {
		A[i]=sc.nextInt();
		if(A[i]>max) {
			secondMax=max;
			max=A[i];
		}else if(A[i]>secondMax) {
			secondMax=A[i];
		}
	}
	for(int i=0;i<N;i++) {
		if(A[i]==max) {
			System.out.println(secondMax);
		}else {
			System.out.println(max);
		}
	}
}
}