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