import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
        int [] in = new int [a];
		int max = 0;
        int point = -1;
        for(int i=0;i<a;i++){
                             in[i] = sc.nextInt();
                             if(max<=in[i]){max = in[i];point=i;}
                            }
        Arrays.sort(in);        		
        for(int i=0;i<a;i++){if(in[a-2]<in[a-1] && i==point)
                            {System.out.println(in[a-2]);}
                            else{System.out.println(in[a-1]);}}        
	}
} import java.util.*; util.* java public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
        int [] in = new int [a];
		int max = 0;
        int point = -1;
        for(int i=0;i<a;i++){
                             in[i] = sc.nextInt();
                             if(max<=in[i]){max = in[i];point=i;}
                            }
        Arrays.sort(in);        		
        for(int i=0;i<a;i++){if(in[a-2]<in[a-1] && i==point)
                            {System.out.println(in[a-2]);}
                            else{System.out.println(in[a-1]);}}        
	}
} Main public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
        int [] in = new int [a];
		int max = 0;
        int point = -1;
        for(int i=0;i<a;i++){
                             in[i] = sc.nextInt();
                             if(max<=in[i]){max = in[i];point=i;}
                            }
        Arrays.sort(in);        		
        for(int i=0;i<a;i++){if(in[a-2]<in[a-1] && i==point)
                            {System.out.println(in[a-2]);}
                            else{System.out.println(in[a-1]);}}        
	} main {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
        int [] in = new int [a];
		int max = 0;
        int point = -1;
        for(int i=0;i<a;i++){
                             in[i] = sc.nextInt();
                             if(max<=in[i]){max = in[i];point=i;}
                            }
        Arrays.sort(in);        		
        for(int i=0;i<a;i++){if(in[a-2]<in[a-1] && i==point)
                            {System.out.println(in[a-2]);}
                            else{System.out.println(in[a-1]);}}        
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int a = sc.nextInt(); a sc.nextInt() sc.nextInt sc int [] in = new int [a]; in new int [a] a int max = 0; max 0 int point = -1; point -1 1 for(int i=0;i<a;i++){
                             in[i] = sc.nextInt();
                             if(max<=in[i]){max = in[i];point=i;}
                            } int i=0; int i=0; i 0 i<a i a i++ i++ i {
                             in[i] = sc.nextInt();
                             if(max<=in[i]){max = in[i];point=i;}
                            } {
                             in[i] = sc.nextInt();
                             if(max<=in[i]){max = in[i];point=i;}
                            } in[i] = sc.nextInt() in[i] in i sc.nextInt() sc.nextInt sc if(max<=in[i]){max = in[i];point=i;} max<=in[i] max in[i] in i {max = in[i];point=i;} max = in[i] max in[i] in i point=i point i Arrays.sort(in) Arrays.sort Arrays in for(int i=0;i<a;i++){if(in[a-2]<in[a-1] && i==point)
                            {System.out.println(in[a-2]);}
                            else{System.out.println(in[a-1]);}} int i=0; int i=0; i 0 i<a i a i++ i++ i {if(in[a-2]<in[a-1] && i==point)
                            {System.out.println(in[a-2]);}
                            else{System.out.println(in[a-1]);}} {if(in[a-2]<in[a-1] && i==point)
                            {System.out.println(in[a-2]);}
                            else{System.out.println(in[a-1]);}} if(in[a-2]<in[a-1] && i==point)
                            {System.out.println(in[a-2]);}
                            else{System.out.println(in[a-1]);} in[a-2]<in[a-1] && i==point in[a-2]<in[a-1] in[a-2] in a-2 a 2 in[a-1] in a-1 a 1 i==point i point {System.out.println(in[a-2]);} System.out.println(in[a-2]) System.out.println System.out System System.out in[a-2] in a-2 a 2 {System.out.println(in[a-1]);} System.out.println(in[a-1]) System.out.println System.out System System.out in[a-1] in a-1 a 1 String[] args args public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
        int [] in = new int [a];
		int max = 0;
        int point = -1;
        for(int i=0;i<a;i++){
                             in[i] = sc.nextInt();
                             if(max<=in[i]){max = in[i];point=i;}
                            }
        Arrays.sort(in);        		
        for(int i=0;i<a;i++){if(in[a-2]<in[a-1] && i==point)
                            {System.out.println(in[a-2]);}
                            else{System.out.println(in[a-1]);}}        
	}
} public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
        int [] in = new int [a];
		int max = 0;
        int point = -1;
        for(int i=0;i<a;i++){
                             in[i] = sc.nextInt();
                             if(max<=in[i]){max = in[i];point=i;}
                            }
        Arrays.sort(in);        		
        for(int i=0;i<a;i++){if(in[a-2]<in[a-1] && i==point)
                            {System.out.println(in[a-2]);}
                            else{System.out.println(in[a-1]);}}        
	}
} Main
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
        int [] in = new int [a];
		int max = 0;
        int point = -1;
        for(int i=0;i<a;i++){
                             in[i] = sc.nextInt();
                             if(max<=in[i]){max = in[i];point=i;}
                            }
        Arrays.sort(in);        		
        for(int i=0;i<a;i++){if(in[a-2]<in[a-1] && i==point)
                            {System.out.println(in[a-2]);}
                            else{System.out.println(in[a-1]);}}        
	}
}
