import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    long max1 = 0;
    long max2 = 0;
    long A[] = new long[N];
    for (int i=0; i<N; i++) {
      A[i] = sc.nextLong();
    }
    for (int i=0; i<N; i++) {
      if(max1 <= A[i]){
        max2 = max1;
        max1 = A[i];
      } else if(max2 <= A[i]){
        max2 = A[i];
      }
    }
    for (int i=0; i<N; i++) {
      if(max1 != A[i]){
        System.out.println(max1);
      } else {
        System.out.println(max2);
      }
    }
  }
} import java.util.*; util.* java public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    long max1 = 0;
    long max2 = 0;
    long A[] = new long[N];
    for (int i=0; i<N; i++) {
      A[i] = sc.nextLong();
    }
    for (int i=0; i<N; i++) {
      if(max1 <= A[i]){
        max2 = max1;
        max1 = A[i];
      } else if(max2 <= A[i]){
        max2 = A[i];
      }
    }
    for (int i=0; i<N; i++) {
      if(max1 != A[i]){
        System.out.println(max1);
      } else {
        System.out.println(max2);
      }
    }
  }
} Main public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    long max1 = 0;
    long max2 = 0;
    long A[] = new long[N];
    for (int i=0; i<N; i++) {
      A[i] = sc.nextLong();
    }
    for (int i=0; i<N; i++) {
      if(max1 <= A[i]){
        max2 = max1;
        max1 = A[i];
      } else if(max2 <= A[i]){
        max2 = A[i];
      }
    }
    for (int i=0; i<N; i++) {
      if(max1 != A[i]){
        System.out.println(max1);
      } else {
        System.out.println(max2);
      }
    }
  } main {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    long max1 = 0;
    long max2 = 0;
    long A[] = new long[N];
    for (int i=0; i<N; i++) {
      A[i] = sc.nextLong();
    }
    for (int i=0; i<N; i++) {
      if(max1 <= A[i]){
        max2 = max1;
        max1 = A[i];
      } else if(max2 <= A[i]){
        max2 = A[i];
      }
    }
    for (int i=0; i<N; i++) {
      if(max1 != A[i]){
        System.out.println(max1);
      } else {
        System.out.println(max2);
      }
    }
  } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int N = sc.nextInt(); N sc.nextInt() sc.nextInt sc long max1 = 0; max1 0 long max2 = 0; max2 0 long A[] = new long[N]; A new long[N] N for (int i=0; i<N; i++) {
      A[i] = sc.nextLong();
    } int i=0; int i=0; i 0 i<N i N i++ i++ i {
      A[i] = sc.nextLong();
    } {
      A[i] = sc.nextLong();
    } A[i] = sc.nextLong() A[i] A i sc.nextLong() sc.nextLong sc for (int i=0; i<N; i++) {
      if(max1 <= A[i]){
        max2 = max1;
        max1 = A[i];
      } else if(max2 <= A[i]){
        max2 = A[i];
      }
    } int i=0; int i=0; i 0 i<N i N i++ i++ i {
      if(max1 <= A[i]){
        max2 = max1;
        max1 = A[i];
      } else if(max2 <= A[i]){
        max2 = A[i];
      }
    } {
      if(max1 <= A[i]){
        max2 = max1;
        max1 = A[i];
      } else if(max2 <= A[i]){
        max2 = A[i];
      }
    } if(max1 <= A[i]){
        max2 = max1;
        max1 = A[i];
      } else if(max2 <= A[i]){
        max2 = A[i];
      } max1 <= A[i] max1 A[i] A i {
        max2 = max1;
        max1 = A[i];
      } max2 = max1 max2 max1 max1 = A[i] max1 A[i] A i if(max2 <= A[i]){
        max2 = A[i];
      } max2 <= A[i] max2 A[i] A i {
        max2 = A[i];
      } max2 = A[i] max2 A[i] A i for (int i=0; i<N; i++) {
      if(max1 != A[i]){
        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(max1 != A[i]){
        System.out.println(max1);
      } else {
        System.out.println(max2);
      }
    } {
      if(max1 != A[i]){
        System.out.println(max1);
      } else {
        System.out.println(max2);
      }
    } if(max1 != A[i]){
        System.out.println(max1);
      } else {
        System.out.println(max2);
      } max1 != A[i] max1 A[i] A i {
        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 sc = new Scanner(System.in);
    int N = sc.nextInt();
    long max1 = 0;
    long max2 = 0;
    long A[] = new long[N];
    for (int i=0; i<N; i++) {
      A[i] = sc.nextLong();
    }
    for (int i=0; i<N; i++) {
      if(max1 <= A[i]){
        max2 = max1;
        max1 = A[i];
      } else if(max2 <= A[i]){
        max2 = A[i];
      }
    }
    for (int i=0; i<N; i++) {
      if(max1 != A[i]){
        System.out.println(max1);
      } else {
        System.out.println(max2);
      }
    }
  }
} public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    long max1 = 0;
    long max2 = 0;
    long A[] = new long[N];
    for (int i=0; i<N; i++) {
      A[i] = sc.nextLong();
    }
    for (int i=0; i<N; i++) {
      if(max1 <= A[i]){
        max2 = max1;
        max1 = A[i];
      } else if(max2 <= A[i]){
        max2 = A[i];
      }
    }
    for (int i=0; i<N; i++) {
      if(max1 != A[i]){
        System.out.println(max1);
      } else {
        System.out.println(max2);
      }
    }
  }
} Main
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    long max1 = 0;
    long max2 = 0;
    long A[] = new long[N];
    for (int i=0; i<N; i++) {
      A[i] = sc.nextLong();
    }
    for (int i=0; i<N; i++) {
      if(max1 <= A[i]){
        max2 = max1;
        max1 = A[i];
      } else if(max2 <= A[i]){
        max2 = A[i];
      }
    }
    for (int i=0; i<N; i++) {
      if(max1 != A[i]){
        System.out.println(max1);
      } else {
        System.out.println(max2);
      }
    }
  }
}