import java.util.*;
class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int[] A = new int[N];
    for (int i = 0; i < N; i++) {
      A[i] = sc.nextInt();
    }
    int[] B = Arrays.stream(A).sorted().toArray();
    int max = B[N-1];
    int nextMax = B[N-2];
    for (int i = 0; i < N; i++) {
      if (A[i] == max) {
        System.out.println(nextMax);
      } else {
        System.out.println(max);
      }
    }
  }
} import java.util.*; util.* java class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int[] A = new int[N];
    for (int i = 0; i < N; i++) {
      A[i] = sc.nextInt();
    }
    int[] B = Arrays.stream(A).sorted().toArray();
    int max = B[N-1];
    int nextMax = B[N-2];
    for (int i = 0; i < N; i++) {
      if (A[i] == max) {
        System.out.println(nextMax);
      } else {
        System.out.println(max);
      }
    }
  }
} Main public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int[] A = new int[N];
    for (int i = 0; i < N; i++) {
      A[i] = sc.nextInt();
    }
    int[] B = Arrays.stream(A).sorted().toArray();
    int max = B[N-1];
    int nextMax = B[N-2];
    for (int i = 0; i < N; i++) {
      if (A[i] == max) {
        System.out.println(nextMax);
      } else {
        System.out.println(max);
      }
    }
  } main {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int[] A = new int[N];
    for (int i = 0; i < N; i++) {
      A[i] = sc.nextInt();
    }
    int[] B = Arrays.stream(A).sorted().toArray();
    int max = B[N-1];
    int nextMax = B[N-2];
    for (int i = 0; i < N; i++) {
      if (A[i] == max) {
        System.out.println(nextMax);
      } else {
        System.out.println(max);
      }
    }
  } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int N = sc.nextInt(); N sc.nextInt() sc.nextInt sc int[] A = new int[N]; A new int[N] N for (int i = 0; i < N; i++) {
      A[i] = sc.nextInt();
    } int i = 0; int 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[] B = Arrays.stream(A).sorted().toArray(); B Arrays.stream(A).sorted().toArray() Arrays.stream(A).sorted().toArray Arrays.stream(A).sorted() Arrays.stream(A).sorted Arrays.stream(A) Arrays.stream Arrays A int max = B[N-1]; max B[N-1] B N-1 N 1 int nextMax = B[N-2]; nextMax B[N-2] B N-2 N 2 for (int i = 0; i < N; i++) {
      if (A[i] == max) {
        System.out.println(nextMax);
      } else {
        System.out.println(max);
      }
    } int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
      if (A[i] == max) {
        System.out.println(nextMax);
      } else {
        System.out.println(max);
      }
    } {
      if (A[i] == max) {
        System.out.println(nextMax);
      } else {
        System.out.println(max);
      }
    } if (A[i] == max) {
        System.out.println(nextMax);
      } else {
        System.out.println(max);
      } A[i] == max A[i] A i max {
        System.out.println(nextMax);
      } System.out.println(nextMax) System.out.println System.out System System.out nextMax {
        System.out.println(max);
      } System.out.println(max) System.out.println System.out System System.out max String[] args args
import java.util.*;
class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int[] A = new int[N];
    for (int i = 0; i < N; i++) {
      A[i] = sc.nextInt();
    }
    int[] B = Arrays.stream(A).sorted().toArray();
    int max = B[N-1];
    int nextMax = B[N-2];
    for (int i = 0; i < N; i++) {
      if (A[i] == max) {
        System.out.println(nextMax);
      } else {
        System.out.println(max);
      }
    }
  }
}