#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
int main() {
  int n;
  vector<int> a(n);
  cin >> n;
  for (int i = 0; i < n; i++) cin >> a[i];
  int mx = 0, smx = 0;
  vector<int> b(n);
  b = a;
  sort(b.begin(), b.end());
  reverse(b.begin(), b.end());
  mx = b[0];
  smx = b[1];
  if (mx == smx) {
    for (int i = 0; i < n; i++) cout << mx << endl;
  } else {
    for (int i = 0; i < n; i++) {
      if (mx == a[i])
        cout << smx << endl;
      else
        cout << mx << endl;
    }
  }
  return 0;
}
