#include <bits/stdc++.h>
using namespace std;
signed main() {
  int D, N, M, O, P, count = 0, count2 = 0, count3 = 0, stack = 0;
  string S, T;
  double l, s;
  cin >> N;
  vector<int> a(N);
  for (int i = 0; i < N; i++) {
    cin >> a[i];
    if (count2 <= a[i]) count2 = i - 1;
  }
  sort(a.begin(), a.end());
  for (int i = 0; i < N; i++) {
    if (i - 1 == count2)
      cout << a[N - 2] << endl;
    else
      cout << a[N - 1] << endl;
  }
}
