import java.util.*;
 
public class Main {
  public static void main (String[] arg) {
    Scanner scan = new Scanner(System.in);
    int N = scan.nextInt();
    int A[] = new int[N];
    int Max = 0;
    int Maxi = 0;
    int Max2 = 0;
    
    for (int i = 0; i < N; i++){
      A[i] = scan.nextInt();
      if(A[i] > Max){
        Max2 = Max;
        Max = A[i];
        Maxi = i;
      } else if(A[i] > Max2){
        Max2 = A[i];
      }
    }
    
    for(int i = 0; i < N; i++){
      if(i == Maxi){
        System.out.println(Max2);
      } else {
        System.out.println(Max);
      }
    }
  }
} import java.util.*; util.* java public class Main {
  public static void main (String[] arg) {
    Scanner scan = new Scanner(System.in);
    int N = scan.nextInt();
    int A[] = new int[N];
    int Max = 0;
    int Maxi = 0;
    int Max2 = 0;
    
    for (int i = 0; i < N; i++){
      A[i] = scan.nextInt();
      if(A[i] > Max){
        Max2 = Max;
        Max = A[i];
        Maxi = i;
      } else if(A[i] > Max2){
        Max2 = A[i];
      }
    }
    
    for(int i = 0; i < N; i++){
      if(i == Maxi){
        System.out.println(Max2);
      } else {
        System.out.println(Max);
      }
    }
  }
} Main public static void main (String[] arg) {
    Scanner scan = new Scanner(System.in);
    int N = scan.nextInt();
    int A[] = new int[N];
    int Max = 0;
    int Maxi = 0;
    int Max2 = 0;
    
    for (int i = 0; i < N; i++){
      A[i] = scan.nextInt();
      if(A[i] > Max){
        Max2 = Max;
        Max = A[i];
        Maxi = i;
      } else if(A[i] > Max2){
        Max2 = A[i];
      }
    }
    
    for(int i = 0; i < N; i++){
      if(i == Maxi){
        System.out.println(Max2);
      } else {
        System.out.println(Max);
      }
    }
  } main {
    Scanner scan = new Scanner(System.in);
    int N = scan.nextInt();
    int A[] = new int[N];
    int Max = 0;
    int Maxi = 0;
    int Max2 = 0;
    
    for (int i = 0; i < N; i++){
      A[i] = scan.nextInt();
      if(A[i] > Max){
        Max2 = Max;
        Max = A[i];
        Maxi = i;
      } else if(A[i] > Max2){
        Max2 = A[i];
      }
    }
    
    for(int i = 0; i < N; i++){
      if(i == Maxi){
        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 A[] = new int[N]; A new int[N] N int Max = 0; Max 0 int Maxi = 0; Maxi 0 int Max2 = 0; Max2 0 for (int i = 0; i < N; i++){
      A[i] = scan.nextInt();
      if(A[i] > Max){
        Max2 = Max;
        Max = A[i];
        Maxi = i;
      } else if(A[i] > Max2){
        Max2 = A[i];
      }
    } int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
      A[i] = scan.nextInt();
      if(A[i] > Max){
        Max2 = Max;
        Max = A[i];
        Maxi = i;
      } else if(A[i] > Max2){
        Max2 = A[i];
      }
    } {
      A[i] = scan.nextInt();
      if(A[i] > Max){
        Max2 = Max;
        Max = A[i];
        Maxi = i;
      } else if(A[i] > Max2){
        Max2 = A[i];
      }
    } A[i] = scan.nextInt() A[i] A i scan.nextInt() scan.nextInt scan if(A[i] > Max){
        Max2 = Max;
        Max = A[i];
        Maxi = i;
      } else if(A[i] > Max2){
        Max2 = A[i];
      } A[i] > Max A[i] A i Max {
        Max2 = Max;
        Max = A[i];
        Maxi = i;
      } Max2 = Max Max2 Max Max = A[i] Max A[i] A i Maxi = i Maxi i if(A[i] > Max2){
        Max2 = A[i];
      } A[i] > Max2 A[i] A i Max2 {
        Max2 = A[i];
      } Max2 = A[i] Max2 A[i] A i for(int i = 0; i < N; i++){
      if(i == Maxi){
        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 == Maxi){
        System.out.println(Max2);
      } else {
        System.out.println(Max);
      }
    } {
      if(i == Maxi){
        System.out.println(Max2);
      } else {
        System.out.println(Max);
      }
    } if(i == Maxi){
        System.out.println(Max2);
      } else {
        System.out.println(Max);
      } i == Maxi i Maxi {
        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[] arg arg public class Main {
  public static void main (String[] arg) {
    Scanner scan = new Scanner(System.in);
    int N = scan.nextInt();
    int A[] = new int[N];
    int Max = 0;
    int Maxi = 0;
    int Max2 = 0;
    
    for (int i = 0; i < N; i++){
      A[i] = scan.nextInt();
      if(A[i] > Max){
        Max2 = Max;
        Max = A[i];
        Maxi = i;
      } else if(A[i] > Max2){
        Max2 = A[i];
      }
    }
    
    for(int i = 0; i < N; i++){
      if(i == Maxi){
        System.out.println(Max2);
      } else {
        System.out.println(Max);
      }
    }
  }
} public class Main {
  public static void main (String[] arg) {
    Scanner scan = new Scanner(System.in);
    int N = scan.nextInt();
    int A[] = new int[N];
    int Max = 0;
    int Maxi = 0;
    int Max2 = 0;
    
    for (int i = 0; i < N; i++){
      A[i] = scan.nextInt();
      if(A[i] > Max){
        Max2 = Max;
        Max = A[i];
        Maxi = i;
      } else if(A[i] > Max2){
        Max2 = A[i];
      }
    }
    
    for(int i = 0; i < N; i++){
      if(i == Maxi){
        System.out.println(Max2);
      } else {
        System.out.println(Max);
      }
    }
  }
} Main
import java.util.*;
 
public class Main {
  public static void main (String[] arg) {
    Scanner scan = new Scanner(System.in);
    int N = scan.nextInt();
    int A[] = new int[N];
    int Max = 0;
    int Maxi = 0;
    int Max2 = 0;
    
    for (int i = 0; i < N; i++){
      A[i] = scan.nextInt();
      if(A[i] > Max){
        Max2 = Max;
        Max = A[i];
        Maxi = i;
      } else if(A[i] > Max2){
        Max2 = A[i];
      }
    }
    
    for(int i = 0; i < N; i++){
      if(i == Maxi){
        System.out.println(Max2);
      } else {
        System.out.println(Max);
      }
    }
  }
}