import java.io.PrintWriter;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);

		int N =scan.nextInt();
		int max=0,midx=0;
		int max2=0,midx2=0;

		for(int i=0; i<N ;i++)
		{
			int a =scan.nextInt();
			if(max<a){
				max=a;
				midx=i;
			}else if(max2<a) {
				max2=a;
				midx2=a;
			}
		}

		for(int i=0;i<N;i++) {
			if(i==midx) {
				System.out.println(max2);
			}else {
				System.out.println(max);
			}
		}



	}
} import java.io.PrintWriter; PrintWriter java.io 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 max=0,midx=0;
		int max2=0,midx2=0;

		for(int i=0; i<N ;i++)
		{
			int a =scan.nextInt();
			if(max<a){
				max=a;
				midx=i;
			}else if(max2<a) {
				max2=a;
				midx2=a;
			}
		}

		for(int i=0;i<N;i++) {
			if(i==midx) {
				System.out.println(max2);
			}else {
				System.out.println(max);
			}
		}



	}
} Main public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);

		int N =scan.nextInt();
		int max=0,midx=0;
		int max2=0,midx2=0;

		for(int i=0; i<N ;i++)
		{
			int a =scan.nextInt();
			if(max<a){
				max=a;
				midx=i;
			}else if(max2<a) {
				max2=a;
				midx2=a;
			}
		}

		for(int i=0;i<N;i++) {
			if(i==midx) {
				System.out.println(max2);
			}else {
				System.out.println(max);
			}
		}



	} main {

		Scanner scan = new Scanner(System.in);

		int N =scan.nextInt();
		int max=0,midx=0;
		int max2=0,midx2=0;

		for(int i=0; i<N ;i++)
		{
			int a =scan.nextInt();
			if(max<a){
				max=a;
				midx=i;
			}else if(max2<a) {
				max2=a;
				midx2=a;
			}
		}

		for(int i=0;i<N;i++) {
			if(i==midx) {
				System.out.println(max2);
			}else {
				System.out.println(max);
			}
		}



	} Scanner scan = new Scanner(System.in); scan new Scanner(System.in) int N =scan.nextInt(); N scan.nextInt() scan.nextInt scan int max=0 max 0 midx=0; midx 0 int max2=0 max2 0 midx2=0; midx2 0 for(int i=0; i<N ;i++)
		{
			int a =scan.nextInt();
			if(max<a){
				max=a;
				midx=i;
			}else if(max2<a) {
				max2=a;
				midx2=a;
			}
		} int i=0; int i=0; i 0 i<N i N i++ i++ i {
			int a =scan.nextInt();
			if(max<a){
				max=a;
				midx=i;
			}else if(max2<a) {
				max2=a;
				midx2=a;
			}
		} {
			int a =scan.nextInt();
			if(max<a){
				max=a;
				midx=i;
			}else if(max2<a) {
				max2=a;
				midx2=a;
			}
		} int a =scan.nextInt(); a scan.nextInt() scan.nextInt scan if(max<a){
				max=a;
				midx=i;
			}else if(max2<a) {
				max2=a;
				midx2=a;
			} max<a max a {
				max=a;
				midx=i;
			} max=a max a midx=i midx i if(max2<a) {
				max2=a;
				midx2=a;
			} max2<a max2 a {
				max2=a;
				midx2=a;
			} max2=a max2 a midx2=a midx2 a for(int i=0;i<N;i++) {
			if(i==midx) {
				System.out.println(max2);
			}else {
				System.out.println(max);
			}
		} int i=0; int i=0; i 0 i<N i N i++ i++ i {
			if(i==midx) {
				System.out.println(max2);
			}else {
				System.out.println(max);
			}
		} {
			if(i==midx) {
				System.out.println(max2);
			}else {
				System.out.println(max);
			}
		} if(i==midx) {
				System.out.println(max2);
			}else {
				System.out.println(max);
			} i==midx i midx {
				System.out.println(max2);
			} System.out.println(max2) System.out.println System.out System System.out max2 {
				System.out.println(max);
			} System.out.println(max) System.out.println System.out System System.out max String[] args args public class Main {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);

		int N =scan.nextInt();
		int max=0,midx=0;
		int max2=0,midx2=0;

		for(int i=0; i<N ;i++)
		{
			int a =scan.nextInt();
			if(max<a){
				max=a;
				midx=i;
			}else if(max2<a) {
				max2=a;
				midx2=a;
			}
		}

		for(int i=0;i<N;i++) {
			if(i==midx) {
				System.out.println(max2);
			}else {
				System.out.println(max);
			}
		}



	}
} public class Main {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);

		int N =scan.nextInt();
		int max=0,midx=0;
		int max2=0,midx2=0;

		for(int i=0; i<N ;i++)
		{
			int a =scan.nextInt();
			if(max<a){
				max=a;
				midx=i;
			}else if(max2<a) {
				max2=a;
				midx2=a;
			}
		}

		for(int i=0;i<N;i++) {
			if(i==midx) {
				System.out.println(max2);
			}else {
				System.out.println(max);
			}
		}



	}
} Main
import java.io.PrintWriter;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);

		int N =scan.nextInt();
		int max=0,midx=0;
		int max2=0,midx2=0;

		for(int i=0; i<N ;i++)
		{
			int a =scan.nextInt();
			if(max<a){
				max=a;
				midx=i;
			}else if(max2<a) {
				max2=a;
				midx2=a;
			}
		}

		for(int i=0;i<N;i++) {
			if(i==midx) {
				System.out.println(max2);
			}else {
				System.out.println(max);
			}
		}



	}
}