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