import java.util.Scanner;
import java.lang.StringBuilder;
import java.math.BigInteger;

public class Main{
  
  
  
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    
    int n;
    n = sc.nextInt();
    
    int[] nums = new int[n];
    boolean another_max = false;
    int max = 0;
    int max2 = 0;
    boolean second = true;
    for (int i=0; i!=n; i+=1){
      int num = sc.nextInt();
      nums[i] = num;
      if (i == 0) {
        max = num;
      }
      else if (i == 1){
        if (num < max){
          max2 = num;
        }
        else{
          max2 = max;
          max = num;
        }
      }
      else{
      if (num == max) another_max = true;
      
      if (num != max){
        if (num > max){
          max2 = max;
          max = num;
          another_max = false;
        }
        else if (num < max && num > max2){
          max2 = num;
        }
      }
      }
    }
    
    if (max2 == 0) max2 = max;
//    System.out.print(max + " " + max2 + " "+ another_max);
    StringBuilder sb = new StringBuilder();
    for (int i=0; i!=n; i+=1){
      if (nums[i] == max && !another_max) sb.append(max2 + "\n");
      else sb.append(max + "\n");
    }
    
    
    
    
    
    System.out.print(sb.toString());
    
    
  }
} import java.util.Scanner; Scanner java.util import java.lang.StringBuilder; StringBuilder java.lang import java.math.BigInteger; BigInteger java.math public class Main{
  
  
  
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    
    int n;
    n = sc.nextInt();
    
    int[] nums = new int[n];
    boolean another_max = false;
    int max = 0;
    int max2 = 0;
    boolean second = true;
    for (int i=0; i!=n; i+=1){
      int num = sc.nextInt();
      nums[i] = num;
      if (i == 0) {
        max = num;
      }
      else if (i == 1){
        if (num < max){
          max2 = num;
        }
        else{
          max2 = max;
          max = num;
        }
      }
      else{
      if (num == max) another_max = true;
      
      if (num != max){
        if (num > max){
          max2 = max;
          max = num;
          another_max = false;
        }
        else if (num < max && num > max2){
          max2 = num;
        }
      }
      }
    }
    
    if (max2 == 0) max2 = max;
//    System.out.print(max + " " + max2 + " "+ another_max);
    StringBuilder sb = new StringBuilder();
    for (int i=0; i!=n; i+=1){
      if (nums[i] == max && !another_max) sb.append(max2 + "\n");
      else sb.append(max + "\n");
    }
    
    
    
    
    
    System.out.print(sb.toString());
    
    
  }
} Main public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    
    int n;
    n = sc.nextInt();
    
    int[] nums = new int[n];
    boolean another_max = false;
    int max = 0;
    int max2 = 0;
    boolean second = true;
    for (int i=0; i!=n; i+=1){
      int num = sc.nextInt();
      nums[i] = num;
      if (i == 0) {
        max = num;
      }
      else if (i == 1){
        if (num < max){
          max2 = num;
        }
        else{
          max2 = max;
          max = num;
        }
      }
      else{
      if (num == max) another_max = true;
      
      if (num != max){
        if (num > max){
          max2 = max;
          max = num;
          another_max = false;
        }
        else if (num < max && num > max2){
          max2 = num;
        }
      }
      }
    }
    
    if (max2 == 0) max2 = max;
//    System.out.print(max + " " + max2 + " "+ another_max);
    StringBuilder sb = new StringBuilder();
    for (int i=0; i!=n; i+=1){
      if (nums[i] == max && !another_max) sb.append(max2 + "\n");
      else sb.append(max + "\n");
    }
    
    
    
    
    
    System.out.print(sb.toString());
    
    
  } main {
    Scanner sc = new Scanner(System.in);
    
    int n;
    n = sc.nextInt();
    
    int[] nums = new int[n];
    boolean another_max = false;
    int max = 0;
    int max2 = 0;
    boolean second = true;
    for (int i=0; i!=n; i+=1){
      int num = sc.nextInt();
      nums[i] = num;
      if (i == 0) {
        max = num;
      }
      else if (i == 1){
        if (num < max){
          max2 = num;
        }
        else{
          max2 = max;
          max = num;
        }
      }
      else{
      if (num == max) another_max = true;
      
      if (num != max){
        if (num > max){
          max2 = max;
          max = num;
          another_max = false;
        }
        else if (num < max && num > max2){
          max2 = num;
        }
      }
      }
    }
    
    if (max2 == 0) max2 = max;
//    System.out.print(max + " " + max2 + " "+ another_max);
    StringBuilder sb = new StringBuilder();
    for (int i=0; i!=n; i+=1){
      if (nums[i] == max && !another_max) sb.append(max2 + "\n");
      else sb.append(max + "\n");
    }
    
    
    
    
    
    System.out.print(sb.toString());
    
    
  } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n; n n = sc.nextInt() n sc.nextInt() sc.nextInt sc int[] nums = new int[n]; nums new int[n] n boolean another_max = false; another_max false int max = 0; max 0 int max2 = 0; max2 0 boolean second = true; second true for (int i=0; i!=n; i+=1){
      int num = sc.nextInt();
      nums[i] = num;
      if (i == 0) {
        max = num;
      }
      else if (i == 1){
        if (num < max){
          max2 = num;
        }
        else{
          max2 = max;
          max = num;
        }
      }
      else{
      if (num == max) another_max = true;
      
      if (num != max){
        if (num > max){
          max2 = max;
          max = num;
          another_max = false;
        }
        else if (num < max && num > max2){
          max2 = num;
        }
      }
      }
    } int i=0; int i=0; i 0 i!=n i n i+=1 i+=1 i 1 {
      int num = sc.nextInt();
      nums[i] = num;
      if (i == 0) {
        max = num;
      }
      else if (i == 1){
        if (num < max){
          max2 = num;
        }
        else{
          max2 = max;
          max = num;
        }
      }
      else{
      if (num == max) another_max = true;
      
      if (num != max){
        if (num > max){
          max2 = max;
          max = num;
          another_max = false;
        }
        else if (num < max && num > max2){
          max2 = num;
        }
      }
      }
    } {
      int num = sc.nextInt();
      nums[i] = num;
      if (i == 0) {
        max = num;
      }
      else if (i == 1){
        if (num < max){
          max2 = num;
        }
        else{
          max2 = max;
          max = num;
        }
      }
      else{
      if (num == max) another_max = true;
      
      if (num != max){
        if (num > max){
          max2 = max;
          max = num;
          another_max = false;
        }
        else if (num < max && num > max2){
          max2 = num;
        }
      }
      }
    } int num = sc.nextInt(); num sc.nextInt() sc.nextInt sc nums[i] = num nums[i] nums i num if (i == 0) {
        max = num;
      }
      else if (i == 1){
        if (num < max){
          max2 = num;
        }
        else{
          max2 = max;
          max = num;
        }
      }
      else{
      if (num == max) another_max = true;
      
      if (num != max){
        if (num > max){
          max2 = max;
          max = num;
          another_max = false;
        }
        else if (num < max && num > max2){
          max2 = num;
        }
      }
      } i == 0 i 0 {
        max = num;
      } max = num max num if (i == 1){
        if (num < max){
          max2 = num;
        }
        else{
          max2 = max;
          max = num;
        }
      }
      else{
      if (num == max) another_max = true;
      
      if (num != max){
        if (num > max){
          max2 = max;
          max = num;
          another_max = false;
        }
        else if (num < max && num > max2){
          max2 = num;
        }
      }
      } i == 1 i 1 {
        if (num < max){
          max2 = num;
        }
        else{
          max2 = max;
          max = num;
        }
      } if (num < max){
          max2 = num;
        }
        else{
          max2 = max;
          max = num;
        } num < max num max {
          max2 = num;
        } max2 = num max2 num {
          max2 = max;
          max = num;
        } max2 = max max2 max max = num max num {
      if (num == max) another_max = true;
      
      if (num != max){
        if (num > max){
          max2 = max;
          max = num;
          another_max = false;
        }
        else if (num < max && num > max2){
          max2 = num;
        }
      }
      } if (num == max) another_max = true; num == max num max another_max = true another_max true if (num != max){
        if (num > max){
          max2 = max;
          max = num;
          another_max = false;
        }
        else if (num < max && num > max2){
          max2 = num;
        }
      } num != max num max {
        if (num > max){
          max2 = max;
          max = num;
          another_max = false;
        }
        else if (num < max && num > max2){
          max2 = num;
        }
      } if (num > max){
          max2 = max;
          max = num;
          another_max = false;
        }
        else if (num < max && num > max2){
          max2 = num;
        } num > max num max {
          max2 = max;
          max = num;
          another_max = false;
        } max2 = max max2 max max = num max num another_max = false another_max false if (num < max && num > max2){
          max2 = num;
        } num < max && num > max2 num < max num max num > max2 num max2 {
          max2 = num;
        } max2 = num max2 num if (max2 == 0) max2 = max; max2 == 0 max2 0 max2 = max max2 max StringBuilder sb = new StringBuilder(); sb new StringBuilder() for (int i=0; i!=n; i+=1){
      if (nums[i] == max && !another_max) sb.append(max2 + "\n");
      else sb.append(max + "\n");
    } int i=0; int i=0; i 0 i!=n i n i+=1 i+=1 i 1 {
      if (nums[i] == max && !another_max) sb.append(max2 + "\n");
      else sb.append(max + "\n");
    } {
      if (nums[i] == max && !another_max) sb.append(max2 + "\n");
      else sb.append(max + "\n");
    } if (nums[i] == max && !another_max) sb.append(max2 + "\n");
      else sb.append(max + "\n"); nums[i] == max && !another_max nums[i] == max nums[i] nums i max !another_max another_max sb.append(max2 + "\n") sb.append sb max2 + "\n" max2 "\n" sb.append(max + "\n") sb.append sb max + "\n" max "\n" System.out.print(sb.toString()) System.out.print System.out System System.out sb.toString() sb.toString sb String[] args args public class Main{
  
  
  
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    
    int n;
    n = sc.nextInt();
    
    int[] nums = new int[n];
    boolean another_max = false;
    int max = 0;
    int max2 = 0;
    boolean second = true;
    for (int i=0; i!=n; i+=1){
      int num = sc.nextInt();
      nums[i] = num;
      if (i == 0) {
        max = num;
      }
      else if (i == 1){
        if (num < max){
          max2 = num;
        }
        else{
          max2 = max;
          max = num;
        }
      }
      else{
      if (num == max) another_max = true;
      
      if (num != max){
        if (num > max){
          max2 = max;
          max = num;
          another_max = false;
        }
        else if (num < max && num > max2){
          max2 = num;
        }
      }
      }
    }
    
    if (max2 == 0) max2 = max;
//    System.out.print(max + " " + max2 + " "+ another_max);
    StringBuilder sb = new StringBuilder();
    for (int i=0; i!=n; i+=1){
      if (nums[i] == max && !another_max) sb.append(max2 + "\n");
      else sb.append(max + "\n");
    }
    
    
    
    
    
    System.out.print(sb.toString());
    
    
  }
} public class Main{
  
  
  
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    
    int n;
    n = sc.nextInt();
    
    int[] nums = new int[n];
    boolean another_max = false;
    int max = 0;
    int max2 = 0;
    boolean second = true;
    for (int i=0; i!=n; i+=1){
      int num = sc.nextInt();
      nums[i] = num;
      if (i == 0) {
        max = num;
      }
      else if (i == 1){
        if (num < max){
          max2 = num;
        }
        else{
          max2 = max;
          max = num;
        }
      }
      else{
      if (num == max) another_max = true;
      
      if (num != max){
        if (num > max){
          max2 = max;
          max = num;
          another_max = false;
        }
        else if (num < max && num > max2){
          max2 = num;
        }
      }
      }
    }
    
    if (max2 == 0) max2 = max;
//    System.out.print(max + " " + max2 + " "+ another_max);
    StringBuilder sb = new StringBuilder();
    for (int i=0; i!=n; i+=1){
      if (nums[i] == max && !another_max) sb.append(max2 + "\n");
      else sb.append(max + "\n");
    }
    
    
    
    
    
    System.out.print(sb.toString());
    
    
  }
} Main
import java.util.Scanner;
import java.lang.StringBuilder;
import java.math.BigInteger;

public class Main{
  
  
  
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    
    int n;
    n = sc.nextInt();
    
    int[] nums = new int[n];
    boolean another_max = false;
    int max = 0;
    int max2 = 0;
    boolean second = true;
    for (int i=0; i!=n; i+=1){
      int num = sc.nextInt();
      nums[i] = num;
      if (i == 0) {
        max = num;
      }
      else if (i == 1){
        if (num < max){
          max2 = num;
        }
        else{
          max2 = max;
          max = num;
        }
      }
      else{
      if (num == max) another_max = true;
      
      if (num != max){
        if (num > max){
          max2 = max;
          max = num;
          another_max = false;
        }
        else if (num < max && num > max2){
          max2 = num;
        }
      }
      }
    }
    
    if (max2 == 0) max2 = max;
//    System.out.print(max + " " + max2 + " "+ another_max);
    StringBuilder sb = new StringBuilder();
    for (int i=0; i!=n; i+=1){
      if (nums[i] == max && !another_max) sb.append(max2 + "\n");
      else sb.append(max + "\n");
    }
    
    
    
    
    
    System.out.print(sb.toString());
    
    
  }
}