import java.util.*; 

class Main{
public static void main(String[] args){
	Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();

  		int[] a=new int[n];
		for(int c=0;c<n;c++){
    		a[c]=sc.nextInt();
    	}
  		int max1=a[0];
  		int max2=0;
  		int b1=0;
  		
  		
  		for(int b=0;b<n-1;b++){
        	if(max1<=a[b+1]){
              	max2=max1;
            	max1=a[b+1];
              	b1=b+1;
              	
            }else if(max2<=a[b+1]){
            	max2=a[b+1];
            }
        }
 
    for(int e=0;e<n;e++){
 	if(e==b1){
    		System.out.println(max2);
    	}else{
     		System.out.println(max1);
   	 }
    }
    }
}
 import java.util.*; util.* java class Main{
public static void main(String[] args){
	Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();

  		int[] a=new int[n];
		for(int c=0;c<n;c++){
    		a[c]=sc.nextInt();
    	}
  		int max1=a[0];
  		int max2=0;
  		int b1=0;
  		
  		
  		for(int b=0;b<n-1;b++){
        	if(max1<=a[b+1]){
              	max2=max1;
            	max1=a[b+1];
              	b1=b+1;
              	
            }else if(max2<=a[b+1]){
            	max2=a[b+1];
            }
        }
 
    for(int e=0;e<n;e++){
 	if(e==b1){
    		System.out.println(max2);
    	}else{
     		System.out.println(max1);
   	 }
    }
    }
} Main public static void main(String[] args){
	Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();

  		int[] a=new int[n];
		for(int c=0;c<n;c++){
    		a[c]=sc.nextInt();
    	}
  		int max1=a[0];
  		int max2=0;
  		int b1=0;
  		
  		
  		for(int b=0;b<n-1;b++){
        	if(max1<=a[b+1]){
              	max2=max1;
            	max1=a[b+1];
              	b1=b+1;
              	
            }else if(max2<=a[b+1]){
            	max2=a[b+1];
            }
        }
 
    for(int e=0;e<n;e++){
 	if(e==b1){
    		System.out.println(max2);
    	}else{
     		System.out.println(max1);
   	 }
    }
    } main {
	Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();

  		int[] a=new int[n];
		for(int c=0;c<n;c++){
    		a[c]=sc.nextInt();
    	}
  		int max1=a[0];
  		int max2=0;
  		int b1=0;
  		
  		
  		for(int b=0;b<n-1;b++){
        	if(max1<=a[b+1]){
              	max2=max1;
            	max1=a[b+1];
              	b1=b+1;
              	
            }else if(max2<=a[b+1]){
            	max2=a[b+1];
            }
        }
 
    for(int e=0;e<n;e++){
 	if(e==b1){
    		System.out.println(max2);
    	}else{
     		System.out.println(max1);
   	 }
    }
    } 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 for(int c=0;c<n;c++){
    		a[c]=sc.nextInt();
    	} int c=0; int c=0; c 0 c<n c n c++ c++ c {
    		a[c]=sc.nextInt();
    	} {
    		a[c]=sc.nextInt();
    	} a[c]=sc.nextInt() a[c] a c sc.nextInt() sc.nextInt sc int max1=a[0]; max1 a[0] a 0 int max2=0; max2 0 int b1=0; b1 0 for(int b=0;b<n-1;b++){
        	if(max1<=a[b+1]){
              	max2=max1;
            	max1=a[b+1];
              	b1=b+1;
              	
            }else if(max2<=a[b+1]){
            	max2=a[b+1];
            }
        } int b=0; int b=0; b 0 b<n-1 b n-1 n 1 b++ b++ b {
        	if(max1<=a[b+1]){
              	max2=max1;
            	max1=a[b+1];
              	b1=b+1;
              	
            }else if(max2<=a[b+1]){
            	max2=a[b+1];
            }
        } {
        	if(max1<=a[b+1]){
              	max2=max1;
            	max1=a[b+1];
              	b1=b+1;
              	
            }else if(max2<=a[b+1]){
            	max2=a[b+1];
            }
        } if(max1<=a[b+1]){
              	max2=max1;
            	max1=a[b+1];
              	b1=b+1;
              	
            }else if(max2<=a[b+1]){
            	max2=a[b+1];
            } max1<=a[b+1] max1 a[b+1] a b+1 b 1 {
              	max2=max1;
            	max1=a[b+1];
              	b1=b+1;
              	
            } max2=max1 max2 max1 max1=a[b+1] max1 a[b+1] a b+1 b 1 b1=b+1 b1 b+1 b 1 if(max2<=a[b+1]){
            	max2=a[b+1];
            } max2<=a[b+1] max2 a[b+1] a b+1 b 1 {
            	max2=a[b+1];
            } max2=a[b+1] max2 a[b+1] a b+1 b 1 for(int e=0;e<n;e++){
 	if(e==b1){
    		System.out.println(max2);
    	}else{
     		System.out.println(max1);
   	 }
    } int e=0; int e=0; e 0 e<n e n e++ e++ e {
 	if(e==b1){
    		System.out.println(max2);
    	}else{
     		System.out.println(max1);
   	 }
    } {
 	if(e==b1){
    		System.out.println(max2);
    	}else{
     		System.out.println(max1);
   	 }
    } if(e==b1){
    		System.out.println(max2);
    	}else{
     		System.out.println(max1);
   	 } e==b1 e b1 {
    		System.out.println(max2);
    	} System.out.println(max2) System.out.println System.out System System.out max2 {
     		System.out.println(max1);
   	 } System.out.println(max1) System.out.println System.out System System.out max1 String[] args args
import java.util.*; 

class Main{
public static void main(String[] args){
	Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();

  		int[] a=new int[n];
		for(int c=0;c<n;c++){
    		a[c]=sc.nextInt();
    	}
  		int max1=a[0];
  		int max2=0;
  		int b1=0;
  		
  		
  		for(int b=0;b<n-1;b++){
        	if(max1<=a[b+1]){
              	max2=max1;
            	max1=a[b+1];
              	b1=b+1;
              	
            }else if(max2<=a[b+1]){
            	max2=a[b+1];
            }
        }
 
    for(int e=0;e<n;e++){
 	if(e==b1){
    		System.out.println(max2);
    	}else{
     		System.out.println(max1);
   	 }
    }
    }
}

