import java.util.Scanner;

class Main{
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int N=sc.nextInt();
		int[] leftmax=new int[N];
		int[] rightmax=new int[N];
		int[] num=new int[N];
		leftmax[0]=0;
		rightmax[N-1]=0;
		for(int i=0; i<N; i++) {
			num[i]=sc.nextInt();
		}
		for(int i=1; i<N; i++) {
			leftmax[i]=Math.max(leftmax[i-1], num[i-1]);
		}
		for(int i=N-1; i>=1; i--) {
			rightmax[i-1]=Math.max(rightmax[i], num[i]);
		}
		for(int i=0; i<N; i++) {
			System.out.println(Math.max(leftmax[i], rightmax[i]));
		}
	}
} import java.util.Scanner; Scanner java.util class Main{
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int N=sc.nextInt();
		int[] leftmax=new int[N];
		int[] rightmax=new int[N];
		int[] num=new int[N];
		leftmax[0]=0;
		rightmax[N-1]=0;
		for(int i=0; i<N; i++) {
			num[i]=sc.nextInt();
		}
		for(int i=1; i<N; i++) {
			leftmax[i]=Math.max(leftmax[i-1], num[i-1]);
		}
		for(int i=N-1; i>=1; i--) {
			rightmax[i-1]=Math.max(rightmax[i], num[i]);
		}
		for(int i=0; i<N; i++) {
			System.out.println(Math.max(leftmax[i], rightmax[i]));
		}
	}
} Main public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int N=sc.nextInt();
		int[] leftmax=new int[N];
		int[] rightmax=new int[N];
		int[] num=new int[N];
		leftmax[0]=0;
		rightmax[N-1]=0;
		for(int i=0; i<N; i++) {
			num[i]=sc.nextInt();
		}
		for(int i=1; i<N; i++) {
			leftmax[i]=Math.max(leftmax[i-1], num[i-1]);
		}
		for(int i=N-1; i>=1; i--) {
			rightmax[i-1]=Math.max(rightmax[i], num[i]);
		}
		for(int i=0; i<N; i++) {
			System.out.println(Math.max(leftmax[i], rightmax[i]));
		}
	} main {
		Scanner sc=new Scanner(System.in);
		int N=sc.nextInt();
		int[] leftmax=new int[N];
		int[] rightmax=new int[N];
		int[] num=new int[N];
		leftmax[0]=0;
		rightmax[N-1]=0;
		for(int i=0; i<N; i++) {
			num[i]=sc.nextInt();
		}
		for(int i=1; i<N; i++) {
			leftmax[i]=Math.max(leftmax[i-1], num[i-1]);
		}
		for(int i=N-1; i>=1; i--) {
			rightmax[i-1]=Math.max(rightmax[i], num[i]);
		}
		for(int i=0; i<N; i++) {
			System.out.println(Math.max(leftmax[i], rightmax[i]));
		}
	} Scanner sc=new Scanner(System.in); sc new Scanner(System.in) int N=sc.nextInt(); N sc.nextInt() sc.nextInt sc int[] leftmax=new int[N]; leftmax new int[N] N int[] rightmax=new int[N]; rightmax new int[N] N int[] num=new int[N]; num new int[N] N leftmax[0]=0 leftmax[0] leftmax 0 0 rightmax[N-1]=0 rightmax[N-1] rightmax N-1 N 1 0 for(int i=0; i<N; i++) {
			num[i]=sc.nextInt();
		} int i=0; int i=0; i 0 i<N i N i++ i++ i {
			num[i]=sc.nextInt();
		} {
			num[i]=sc.nextInt();
		} num[i]=sc.nextInt() num[i] num i sc.nextInt() sc.nextInt sc for(int i=1; i<N; i++) {
			leftmax[i]=Math.max(leftmax[i-1], num[i-1]);
		} int i=1; int i=1; i 1 i<N i N i++ i++ i {
			leftmax[i]=Math.max(leftmax[i-1], num[i-1]);
		} {
			leftmax[i]=Math.max(leftmax[i-1], num[i-1]);
		} leftmax[i]=Math.max(leftmax[i-1], num[i-1]) leftmax[i] leftmax i Math.max(leftmax[i-1], num[i-1]) Math.max Math leftmax[i-1] leftmax i-1 i 1 num[i-1] num i-1 i 1 for(int i=N-1; i>=1; i--) {
			rightmax[i-1]=Math.max(rightmax[i], num[i]);
		} int i=N-1; int i=N-1; i N-1 N 1 i>=1 i 1 i-- i-- i {
			rightmax[i-1]=Math.max(rightmax[i], num[i]);
		} {
			rightmax[i-1]=Math.max(rightmax[i], num[i]);
		} rightmax[i-1]=Math.max(rightmax[i], num[i]) rightmax[i-1] rightmax i-1 i 1 Math.max(rightmax[i], num[i]) Math.max Math rightmax[i] rightmax i num[i] num i for(int i=0; i<N; i++) {
			System.out.println(Math.max(leftmax[i], rightmax[i]));
		} int i=0; int i=0; i 0 i<N i N i++ i++ i {
			System.out.println(Math.max(leftmax[i], rightmax[i]));
		} {
			System.out.println(Math.max(leftmax[i], rightmax[i]));
		} System.out.println(Math.max(leftmax[i], rightmax[i])) System.out.println System.out System System.out Math.max(leftmax[i], rightmax[i]) Math.max Math leftmax[i] leftmax i rightmax[i] rightmax i String[] args args
import java.util.Scanner;

class Main{
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int N=sc.nextInt();
		int[] leftmax=new int[N];
		int[] rightmax=new int[N];
		int[] num=new int[N];
		leftmax[0]=0;
		rightmax[N-1]=0;
		for(int i=0; i<N; i++) {
			num[i]=sc.nextInt();
		}
		for(int i=1; i<N; i++) {
			leftmax[i]=Math.max(leftmax[i-1], num[i-1]);
		}
		for(int i=N-1; i>=1; i--) {
			rightmax[i-1]=Math.max(rightmax[i], num[i]);
		}
		for(int i=0; i<N; i++) {
			System.out.println(Math.max(leftmax[i], rightmax[i]));
		}
	}
}