#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  vector<int> unko(N);
  vector<int> unchi(N, 0);
  vector<int> aa(N, 0);
  int comp;
  int second;
  for (int i = 0; i < N; i++) {
    cin >> unko.at(i);
  }
  comp = 0;
  for (int i = 0; i < N; i++) {
    comp = max(comp, unko.at(i));
  }
  for (int i = 0; i < N; i++) {
    if (unko.at(i) == comp) {
      aa.at(i) = 1;
    }
  }
  unchi = unko;
  for (int i = 0; i < N; i++) {
    if (unchi.at(i) == comp) {
      unchi.at(i) = 0;
    }
  }
  sort(unchi.begin(), unchi.end());
  second = unchi.at(N - 1);
  for (int i = 0; i < N; i++) {
    if (aa.at(i) == 0) {
      cout << comp << endl;
    } else {
      cout << second << endl;
    }
  }
}
