#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  vector<int> vec(N);
  for (int i = 0; i < N; i++) {
    cin >> vec.at(i);
  }
  sort(vec.begin(), vec.end());
  int max1 = vec.at(N - 1);
  int max2 = vec.at(N - 2);
  for (int i = 0; i < N; i++) {
    if (vec.at(i) == max1)
      cout << max2 << endl;
    else
      cout << max1 << endl;
  }
}
