import java.util.*;
 
public class Main {
	public static void main (String[] args) {
		Scanner in = new Scanner(System.in);
		
		int N = in.nextInt();
        Integer nam[] = new Integer[N];
        int max1 = 0;int max2 = 0;
      
      for(int i = 0;i < N ; i++){nam[i] =  in.nextInt();}
      
      Integer[] nam2 = nam.clone();
      Arrays.sort(nam, Collections.reverseOrder());
      max1 = nam[0];max2 = nam[1];
      
      for(int i = 0;i < N ; i++){
        if(nam2[i]!=max1){System.out.println(max1);}
        else{System.out.println(max2);}
        
      }
	}
} import java.util.*; util.* java public class Main {
	public static void main (String[] args) {
		Scanner in = new Scanner(System.in);
		
		int N = in.nextInt();
        Integer nam[] = new Integer[N];
        int max1 = 0;int max2 = 0;
      
      for(int i = 0;i < N ; i++){nam[i] =  in.nextInt();}
      
      Integer[] nam2 = nam.clone();
      Arrays.sort(nam, Collections.reverseOrder());
      max1 = nam[0];max2 = nam[1];
      
      for(int i = 0;i < N ; i++){
        if(nam2[i]!=max1){System.out.println(max1);}
        else{System.out.println(max2);}
        
      }
	}
} Main public static void main (String[] args) {
		Scanner in = new Scanner(System.in);
		
		int N = in.nextInt();
        Integer nam[] = new Integer[N];
        int max1 = 0;int max2 = 0;
      
      for(int i = 0;i < N ; i++){nam[i] =  in.nextInt();}
      
      Integer[] nam2 = nam.clone();
      Arrays.sort(nam, Collections.reverseOrder());
      max1 = nam[0];max2 = nam[1];
      
      for(int i = 0;i < N ; i++){
        if(nam2[i]!=max1){System.out.println(max1);}
        else{System.out.println(max2);}
        
      }
	} main {
		Scanner in = new Scanner(System.in);
		
		int N = in.nextInt();
        Integer nam[] = new Integer[N];
        int max1 = 0;int max2 = 0;
      
      for(int i = 0;i < N ; i++){nam[i] =  in.nextInt();}
      
      Integer[] nam2 = nam.clone();
      Arrays.sort(nam, Collections.reverseOrder());
      max1 = nam[0];max2 = nam[1];
      
      for(int i = 0;i < N ; i++){
        if(nam2[i]!=max1){System.out.println(max1);}
        else{System.out.println(max2);}
        
      }
	} Scanner in = new Scanner(System.in); in new Scanner(System.in) int N = in.nextInt(); N in.nextInt() in.nextInt in Integer nam[] = new Integer[N]; nam new Integer[N] N int max1 = 0; max1 0 int max2 = 0; max2 0 for(int i = 0;i < N ; i++){nam[i] =  in.nextInt();} int i = 0; int i = 0; i 0 i < N i N i++ i++ i {nam[i] =  in.nextInt();} {nam[i] =  in.nextInt();} nam[i] =  in.nextInt() nam[i] nam i in.nextInt() in.nextInt in Integer[] nam2 = nam.clone(); nam2 nam.clone() nam.clone nam Arrays.sort(nam, Collections.reverseOrder()) Arrays.sort Arrays nam Collections.reverseOrder() Collections.reverseOrder Collections max1 = nam[0] max1 nam[0] nam 0 max2 = nam[1] max2 nam[1] nam 1 for(int i = 0;i < N ; i++){
        if(nam2[i]!=max1){System.out.println(max1);}
        else{System.out.println(max2);}
        
      } int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
        if(nam2[i]!=max1){System.out.println(max1);}
        else{System.out.println(max2);}
        
      } {
        if(nam2[i]!=max1){System.out.println(max1);}
        else{System.out.println(max2);}
        
      } if(nam2[i]!=max1){System.out.println(max1);}
        else{System.out.println(max2);} nam2[i]!=max1 nam2[i] nam2 i max1 {System.out.println(max1);} System.out.println(max1) System.out.println System.out System System.out max1 {System.out.println(max2);} System.out.println(max2) System.out.println System.out System System.out max2 String[] args args public class Main {
	public static void main (String[] args) {
		Scanner in = new Scanner(System.in);
		
		int N = in.nextInt();
        Integer nam[] = new Integer[N];
        int max1 = 0;int max2 = 0;
      
      for(int i = 0;i < N ; i++){nam[i] =  in.nextInt();}
      
      Integer[] nam2 = nam.clone();
      Arrays.sort(nam, Collections.reverseOrder());
      max1 = nam[0];max2 = nam[1];
      
      for(int i = 0;i < N ; i++){
        if(nam2[i]!=max1){System.out.println(max1);}
        else{System.out.println(max2);}
        
      }
	}
} public class Main {
	public static void main (String[] args) {
		Scanner in = new Scanner(System.in);
		
		int N = in.nextInt();
        Integer nam[] = new Integer[N];
        int max1 = 0;int max2 = 0;
      
      for(int i = 0;i < N ; i++){nam[i] =  in.nextInt();}
      
      Integer[] nam2 = nam.clone();
      Arrays.sort(nam, Collections.reverseOrder());
      max1 = nam[0];max2 = nam[1];
      
      for(int i = 0;i < N ; i++){
        if(nam2[i]!=max1){System.out.println(max1);}
        else{System.out.println(max2);}
        
      }
	}
} Main
import java.util.*;
 
public class Main {
	public static void main (String[] args) {
		Scanner in = new Scanner(System.in);
		
		int N = in.nextInt();
        Integer nam[] = new Integer[N];
        int max1 = 0;int max2 = 0;
      
      for(int i = 0;i < N ; i++){nam[i] =  in.nextInt();}
      
      Integer[] nam2 = nam.clone();
      Arrays.sort(nam, Collections.reverseOrder());
      max1 = nam[0];max2 = nam[1];
      
      for(int i = 0;i < N ; i++){
        if(nam2[i]!=max1){System.out.println(max1);}
        else{System.out.println(max2);}
        
      }
	}
}