#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  long long n;
  cin >> n;
  long long mx = -1, mx1 = -1, cnt = 0, a[n], idx = 0;
  for (long long i = 0; i < n; ++i) {
    cin >> a[i];
    mx = max(mx, a[i]);
  }
  for (long long i = 0; i < n; ++i)
    if (a[i] == mx) cnt++, idx = i;
  if (cnt == 2)
    for (long long i = 0; i < n; ++i) cout << mx << "\n";
  else {
    for (long long i = 0; i < n; ++i)
      if (i != idx) mx1 = max(mx1, a[i]);
    for (long long i = 0; i < n; ++i) {
      if (i != idx)
        cout << mx1 << "\n";
      else
        cout << "\n";
    }
  }
  return 0;
}
