import java.util.*;
import java.util.stream.*;

public class Main {
  public static void main(String[] args) throws Exception {
    Scanner in = new Scanner(System.in);
    int N = in.nextInt();
    int[] A = new int[N];
    int[] B = new int[N];
    for (int i = 0; i < N; i++) {
      A[i] = B[i] = in.nextInt();
    }
    Arrays.sort(B);
    if (B[N - 1] == B[N - 2]) {
      for (int i = 0; i < N; i++) {
        System.out.println(B[N - 1]);
      }
    } else {
      for (int i = 0; i < N; i++) {
        System.out.println(A[i] == B[N - 1] ? B[N - 2] : B[N - 1]);
      }
    }
  }
} import java.util.*; util.* java import java.util.stream.*; stream.* java.util public class Main {
  public static void main(String[] args) throws Exception {
    Scanner in = new Scanner(System.in);
    int N = in.nextInt();
    int[] A = new int[N];
    int[] B = new int[N];
    for (int i = 0; i < N; i++) {
      A[i] = B[i] = in.nextInt();
    }
    Arrays.sort(B);
    if (B[N - 1] == B[N - 2]) {
      for (int i = 0; i < N; i++) {
        System.out.println(B[N - 1]);
      }
    } else {
      for (int i = 0; i < N; i++) {
        System.out.println(A[i] == B[N - 1] ? B[N - 2] : B[N - 1]);
      }
    }
  }
} Main public static void main(String[] args) throws Exception {
    Scanner in = new Scanner(System.in);
    int N = in.nextInt();
    int[] A = new int[N];
    int[] B = new int[N];
    for (int i = 0; i < N; i++) {
      A[i] = B[i] = in.nextInt();
    }
    Arrays.sort(B);
    if (B[N - 1] == B[N - 2]) {
      for (int i = 0; i < N; i++) {
        System.out.println(B[N - 1]);
      }
    } else {
      for (int i = 0; i < N; i++) {
        System.out.println(A[i] == B[N - 1] ? B[N - 2] : B[N - 1]);
      }
    }
  } main {
    Scanner in = new Scanner(System.in);
    int N = in.nextInt();
    int[] A = new int[N];
    int[] B = new int[N];
    for (int i = 0; i < N; i++) {
      A[i] = B[i] = in.nextInt();
    }
    Arrays.sort(B);
    if (B[N - 1] == B[N - 2]) {
      for (int i = 0; i < N; i++) {
        System.out.println(B[N - 1]);
      }
    } else {
      for (int i = 0; i < N; i++) {
        System.out.println(A[i] == B[N - 1] ? B[N - 2] : B[N - 1]);
      }
    }
  } Scanner in = new Scanner(System.in); in new Scanner(System.in) int N = in.nextInt(); N in.nextInt() in.nextInt in int[] A = new int[N]; A new int[N] N int[] B = new int[N]; B new int[N] N for (int i = 0; i < N; i++) {
      A[i] = B[i] = in.nextInt();
    } int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
      A[i] = B[i] = in.nextInt();
    } {
      A[i] = B[i] = in.nextInt();
    } A[i] = B[i] = in.nextInt() A[i] A i B[i] = in.nextInt() B[i] B i in.nextInt() in.nextInt in Arrays.sort(B) Arrays.sort Arrays B if (B[N - 1] == B[N - 2]) {
      for (int i = 0; i < N; i++) {
        System.out.println(B[N - 1]);
      }
    } else {
      for (int i = 0; i < N; i++) {
        System.out.println(A[i] == B[N - 1] ? B[N - 2] : B[N - 1]);
      }
    } B[N - 1] == B[N - 2] B[N - 1] B N - 1 N 1 B[N - 2] B N - 2 N 2 {
      for (int i = 0; i < N; i++) {
        System.out.println(B[N - 1]);
      }
    } for (int i = 0; i < N; i++) {
        System.out.println(B[N - 1]);
      } int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
        System.out.println(B[N - 1]);
      } {
        System.out.println(B[N - 1]);
      } System.out.println(B[N - 1]) System.out.println System.out System System.out B[N - 1] B N - 1 N 1 {
      for (int i = 0; i < N; i++) {
        System.out.println(A[i] == B[N - 1] ? B[N - 2] : B[N - 1]);
      }
    } for (int i = 0; i < N; i++) {
        System.out.println(A[i] == B[N - 1] ? B[N - 2] : B[N - 1]);
      } int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
        System.out.println(A[i] == B[N - 1] ? B[N - 2] : B[N - 1]);
      } {
        System.out.println(A[i] == B[N - 1] ? B[N - 2] : B[N - 1]);
      } System.out.println(A[i] == B[N - 1] ? B[N - 2] : B[N - 1]) System.out.println System.out System System.out A[i] == B[N - 1] ? B[N - 2] : B[N - 1] A[i] == B[N - 1] A[i] A i B[N - 1] B N - 1 N 1 B[N - 2] B N - 2 N 2 B[N - 1] B N - 1 N 1 String[] args args public class Main {
  public static void main(String[] args) throws Exception {
    Scanner in = new Scanner(System.in);
    int N = in.nextInt();
    int[] A = new int[N];
    int[] B = new int[N];
    for (int i = 0; i < N; i++) {
      A[i] = B[i] = in.nextInt();
    }
    Arrays.sort(B);
    if (B[N - 1] == B[N - 2]) {
      for (int i = 0; i < N; i++) {
        System.out.println(B[N - 1]);
      }
    } else {
      for (int i = 0; i < N; i++) {
        System.out.println(A[i] == B[N - 1] ? B[N - 2] : B[N - 1]);
      }
    }
  }
} public class Main {
  public static void main(String[] args) throws Exception {
    Scanner in = new Scanner(System.in);
    int N = in.nextInt();
    int[] A = new int[N];
    int[] B = new int[N];
    for (int i = 0; i < N; i++) {
      A[i] = B[i] = in.nextInt();
    }
    Arrays.sort(B);
    if (B[N - 1] == B[N - 2]) {
      for (int i = 0; i < N; i++) {
        System.out.println(B[N - 1]);
      }
    } else {
      for (int i = 0; i < N; i++) {
        System.out.println(A[i] == B[N - 1] ? B[N - 2] : B[N - 1]);
      }
    }
  }
} Main
import java.util.*;
import java.util.stream.*;

public class Main {
  public static void main(String[] args) throws Exception {
    Scanner in = new Scanner(System.in);
    int N = in.nextInt();
    int[] A = new int[N];
    int[] B = new int[N];
    for (int i = 0; i < N; i++) {
      A[i] = B[i] = in.nextInt();
    }
    Arrays.sort(B);
    if (B[N - 1] == B[N - 2]) {
      for (int i = 0; i < N; i++) {
        System.out.println(B[N - 1]);
      }
    } else {
      for (int i = 0; i < N; i++) {
        System.out.println(A[i] == B[N - 1] ? B[N - 2] : B[N - 1]);
      }
    }
  }
}