#include <bits/stdc++.h>
using namespace std;
bool is_int_lround(double x) { return std::lround(x) == x; }
int ketasuu(int x) {
  int n = 0;
  while (x > 0) {
    x /= 10;
    n++;
  }
  return n;
}
int main() {
  int N;
  cin >> N;
  vector<int> a(N);
  for (int i = 0; i < N; i++) {
    cin >> a.at(i);
  }
  vector<int> b(N);
  for (int i = 0; i < N; i++) {
    b.at(i) = a.at(i);
  }
  sort(b.begin(), b.end());
  int max1 = b[N - 1], max2 = 0;
  for (int i = 0; i < N; i++) {
    if (b[N - 1 - i] != b[N - 2 - i]) {
      max2 = b[N - 2 - i];
      break;
    }
  }
  for (int i = 0; i < N; i++) {
    if (a[i] == max1 && max2 != 0) {
      cout << max2 << endl;
    } else if (a[i] == max1 && max2 == 0) {
      cout << max1 << endl;
    } else {
      cout << max1 << endl;
    }
  }
}
