#include <bits/stdc++.h>
using ll = long long;
using namespace std;
ll mod = 1e9 + 7;
int main() {
  int N;
  ll A[100000];
  cin >> N;
  for (int i(0); i < N; i++) cin >> A[i];
  sort(A, A + N);
  int maxi(A[N - 1]), maxi2(A[N - 2]);
  if (maxi == maxi2) {
    for (int i(0); i < N; i++) {
      cout << maxi << endl;
    }
  } else {
    for (int i(0); i < N; i++) {
      if (A[i] == maxi)
        cout << maxi2 << endl;
      else
        cout << maxi << endl;
    }
  }
  return 0;
}
