

import java.util.Scanner;

public class Main {

	public static void main(String args[])
	{
		Scanner scan=new Scanner(System.in);
		int n=scan.nextInt();
		int ar[]=new int[n];
		for(int i=0;i<n;i++)
		{
			ar[i]=scan.nextInt();
		}
		int left[]=new int[n];
		int right[]=new int[n];
		for(int i=0;i<n;i++)
		{
			if(i==0)left[i]=ar[i];else
				left[i]=Math.max(ar[i],left[i-1]);
		}
		for(int i=n-1;i>=0;i--)
		{
			if(i==n-1)
			{
				right[i]=ar[i];
			}else{
				right[i]=Math.max(ar[i],right[i+1]);
			}
		}
		for(int i=0;i<n;i++)
		{
			if(i==0)
			{
				System.out.println(right[i+1]);
			}else if(i==n-1)
			{
				System.out.println(left[n-2]);
			}else {
			System.out.println(Math.max(left[i-1],right[i+1]));
			}
			}
	}
} 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 ar[]=new int[n];
		for(int i=0;i<n;i++)
		{
			ar[i]=scan.nextInt();
		}
		int left[]=new int[n];
		int right[]=new int[n];
		for(int i=0;i<n;i++)
		{
			if(i==0)left[i]=ar[i];else
				left[i]=Math.max(ar[i],left[i-1]);
		}
		for(int i=n-1;i>=0;i--)
		{
			if(i==n-1)
			{
				right[i]=ar[i];
			}else{
				right[i]=Math.max(ar[i],right[i+1]);
			}
		}
		for(int i=0;i<n;i++)
		{
			if(i==0)
			{
				System.out.println(right[i+1]);
			}else if(i==n-1)
			{
				System.out.println(left[n-2]);
			}else {
			System.out.println(Math.max(left[i-1],right[i+1]));
			}
			}
	}
} Main public static void main(String args[])
	{
		Scanner scan=new Scanner(System.in);
		int n=scan.nextInt();
		int ar[]=new int[n];
		for(int i=0;i<n;i++)
		{
			ar[i]=scan.nextInt();
		}
		int left[]=new int[n];
		int right[]=new int[n];
		for(int i=0;i<n;i++)
		{
			if(i==0)left[i]=ar[i];else
				left[i]=Math.max(ar[i],left[i-1]);
		}
		for(int i=n-1;i>=0;i--)
		{
			if(i==n-1)
			{
				right[i]=ar[i];
			}else{
				right[i]=Math.max(ar[i],right[i+1]);
			}
		}
		for(int i=0;i<n;i++)
		{
			if(i==0)
			{
				System.out.println(right[i+1]);
			}else if(i==n-1)
			{
				System.out.println(left[n-2]);
			}else {
			System.out.println(Math.max(left[i-1],right[i+1]));
			}
			}
	} main {
		Scanner scan=new Scanner(System.in);
		int n=scan.nextInt();
		int ar[]=new int[n];
		for(int i=0;i<n;i++)
		{
			ar[i]=scan.nextInt();
		}
		int left[]=new int[n];
		int right[]=new int[n];
		for(int i=0;i<n;i++)
		{
			if(i==0)left[i]=ar[i];else
				left[i]=Math.max(ar[i],left[i-1]);
		}
		for(int i=n-1;i>=0;i--)
		{
			if(i==n-1)
			{
				right[i]=ar[i];
			}else{
				right[i]=Math.max(ar[i],right[i+1]);
			}
		}
		for(int i=0;i<n;i++)
		{
			if(i==0)
			{
				System.out.println(right[i+1]);
			}else if(i==n-1)
			{
				System.out.println(left[n-2]);
			}else {
			System.out.println(Math.max(left[i-1],right[i+1]));
			}
			}
	} Scanner scan=new Scanner(System.in); scan new Scanner(System.in) int n=scan.nextInt(); n scan.nextInt() scan.nextInt scan int ar[]=new int[n]; ar new int[n] n for(int i=0;i<n;i++)
		{
			ar[i]=scan.nextInt();
		} int i=0; int i=0; i 0 i<n i n i++ i++ i {
			ar[i]=scan.nextInt();
		} {
			ar[i]=scan.nextInt();
		} ar[i]=scan.nextInt() ar[i] ar i scan.nextInt() scan.nextInt scan int left[]=new int[n]; left new int[n] n int right[]=new int[n]; right new int[n] n for(int i=0;i<n;i++)
		{
			if(i==0)left[i]=ar[i];else
				left[i]=Math.max(ar[i],left[i-1]);
		} int i=0; int i=0; i 0 i<n i n i++ i++ i {
			if(i==0)left[i]=ar[i];else
				left[i]=Math.max(ar[i],left[i-1]);
		} {
			if(i==0)left[i]=ar[i];else
				left[i]=Math.max(ar[i],left[i-1]);
		} if(i==0)left[i]=ar[i];else
				left[i]=Math.max(ar[i],left[i-1]); i==0 i 0 left[i]=ar[i] left[i] left i ar[i] ar i left[i]=Math.max(ar[i],left[i-1]) left[i] left i Math.max(ar[i],left[i-1]) Math.max Math ar[i] ar i left[i-1] left i-1 i 1 for(int i=n-1;i>=0;i--)
		{
			if(i==n-1)
			{
				right[i]=ar[i];
			}else{
				right[i]=Math.max(ar[i],right[i+1]);
			}
		} int i=n-1; int i=n-1; i n-1 n 1 i>=0 i 0 i-- i-- i {
			if(i==n-1)
			{
				right[i]=ar[i];
			}else{
				right[i]=Math.max(ar[i],right[i+1]);
			}
		} {
			if(i==n-1)
			{
				right[i]=ar[i];
			}else{
				right[i]=Math.max(ar[i],right[i+1]);
			}
		} if(i==n-1)
			{
				right[i]=ar[i];
			}else{
				right[i]=Math.max(ar[i],right[i+1]);
			} i==n-1 i n-1 n 1 {
				right[i]=ar[i];
			} right[i]=ar[i] right[i] right i ar[i] ar i {
				right[i]=Math.max(ar[i],right[i+1]);
			} right[i]=Math.max(ar[i],right[i+1]) right[i] right i Math.max(ar[i],right[i+1]) Math.max Math ar[i] ar i right[i+1] right i+1 i 1 for(int i=0;i<n;i++)
		{
			if(i==0)
			{
				System.out.println(right[i+1]);
			}else if(i==n-1)
			{
				System.out.println(left[n-2]);
			}else {
			System.out.println(Math.max(left[i-1],right[i+1]));
			}
			} int i=0; int i=0; i 0 i<n i n i++ i++ i {
			if(i==0)
			{
				System.out.println(right[i+1]);
			}else if(i==n-1)
			{
				System.out.println(left[n-2]);
			}else {
			System.out.println(Math.max(left[i-1],right[i+1]));
			}
			} {
			if(i==0)
			{
				System.out.println(right[i+1]);
			}else if(i==n-1)
			{
				System.out.println(left[n-2]);
			}else {
			System.out.println(Math.max(left[i-1],right[i+1]));
			}
			} if(i==0)
			{
				System.out.println(right[i+1]);
			}else if(i==n-1)
			{
				System.out.println(left[n-2]);
			}else {
			System.out.println(Math.max(left[i-1],right[i+1]));
			} i==0 i 0 {
				System.out.println(right[i+1]);
			} System.out.println(right[i+1]) System.out.println System.out System System.out right[i+1] right i+1 i 1 if(i==n-1)
			{
				System.out.println(left[n-2]);
			}else {
			System.out.println(Math.max(left[i-1],right[i+1]));
			} i==n-1 i n-1 n 1 {
				System.out.println(left[n-2]);
			} System.out.println(left[n-2]) System.out.println System.out System System.out left[n-2] left n-2 n 2 {
			System.out.println(Math.max(left[i-1],right[i+1]));
			} System.out.println(Math.max(left[i-1],right[i+1])) System.out.println System.out System System.out Math.max(left[i-1],right[i+1]) Math.max Math left[i-1] left i-1 i 1 right[i+1] right i+1 i 1 String args[] args public class Main {

	public static void main(String args[])
	{
		Scanner scan=new Scanner(System.in);
		int n=scan.nextInt();
		int ar[]=new int[n];
		for(int i=0;i<n;i++)
		{
			ar[i]=scan.nextInt();
		}
		int left[]=new int[n];
		int right[]=new int[n];
		for(int i=0;i<n;i++)
		{
			if(i==0)left[i]=ar[i];else
				left[i]=Math.max(ar[i],left[i-1]);
		}
		for(int i=n-1;i>=0;i--)
		{
			if(i==n-1)
			{
				right[i]=ar[i];
			}else{
				right[i]=Math.max(ar[i],right[i+1]);
			}
		}
		for(int i=0;i<n;i++)
		{
			if(i==0)
			{
				System.out.println(right[i+1]);
			}else if(i==n-1)
			{
				System.out.println(left[n-2]);
			}else {
			System.out.println(Math.max(left[i-1],right[i+1]));
			}
			}
	}
} public class Main {

	public static void main(String args[])
	{
		Scanner scan=new Scanner(System.in);
		int n=scan.nextInt();
		int ar[]=new int[n];
		for(int i=0;i<n;i++)
		{
			ar[i]=scan.nextInt();
		}
		int left[]=new int[n];
		int right[]=new int[n];
		for(int i=0;i<n;i++)
		{
			if(i==0)left[i]=ar[i];else
				left[i]=Math.max(ar[i],left[i-1]);
		}
		for(int i=n-1;i>=0;i--)
		{
			if(i==n-1)
			{
				right[i]=ar[i];
			}else{
				right[i]=Math.max(ar[i],right[i+1]);
			}
		}
		for(int i=0;i<n;i++)
		{
			if(i==0)
			{
				System.out.println(right[i+1]);
			}else if(i==n-1)
			{
				System.out.println(left[n-2]);
			}else {
			System.out.println(Math.max(left[i-1],right[i+1]));
			}
			}
	}
} 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 ar[]=new int[n];
		for(int i=0;i<n;i++)
		{
			ar[i]=scan.nextInt();
		}
		int left[]=new int[n];
		int right[]=new int[n];
		for(int i=0;i<n;i++)
		{
			if(i==0)left[i]=ar[i];else
				left[i]=Math.max(ar[i],left[i-1]);
		}
		for(int i=n-1;i>=0;i--)
		{
			if(i==n-1)
			{
				right[i]=ar[i];
			}else{
				right[i]=Math.max(ar[i],right[i+1]);
			}
		}
		for(int i=0;i<n;i++)
		{
			if(i==0)
			{
				System.out.println(right[i+1]);
			}else if(i==n-1)
			{
				System.out.println(left[n-2]);
			}else {
			System.out.println(Math.max(left[i-1],right[i+1]));
			}
			}
	}
}
