import java.util.*;
import java.util.Arrays;

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

class Main {
  public static void main(String[] args) {
  	Scanner sc = new Scanner(System.in);
  	int N = sc.nextInt();
    int input[] = new int[N];
    int newput[] = new int[N];
    int a = 0;
    for (int i = 0; i < N ; i++){
    	a = sc.nextInt();
        input[i] = a;
        newput[i] = a;
	}
    Arrays.sort(newput);
    int first = newput[N-1];
    int second = newput[N-2];
    if ( first == second ) {
      for ( int i = 0; i < N ; i++){
      	System.out.println(first);
      }
    }
    else {
 		for ( int i = 0; i < N ; i++){
          if ( input[i] == first ){
            System.out.println(second);
          }
          else {
            System.out.println(first);
          }
      }  
    }
        
    }
}