#include <bits/stdc++.h>
using namespace std;
bool distinct(int N, int X, vector<int> A) {
  bool is = true;
  int count = 0;
  for (int i = 0; i < N; i++) {
    if (X == A[i]) count++;
  }
  if (count > 1) is = false;
  return is;
}
int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  int first = 0;
  int second = 0;
  for (int i = 0; i < N; i++) {
    first = max(first, A[i]);
  }
  for (int i = 0; i < N; i++) {
    if (A[i] < first) second = max(second, A[i]);
  }
  for (int i = 0; i < N; i++) {
    if (A[i] == first && distinct(N, A[i], A))
      cout << second << endl;
    else
      cout << first << endl;
  }
  return 0;
}
