#include <bits/stdc++.h>
using namespace std;
int main() {
  long long r, n;
  cin >> n;
  vector<long long> a;
  set<long long> b;
  for (long long i = 0; i < n; i++) {
    long long z;
    cin >> z;
    a.push_back(z);
    b.insert(z);
  }
  vector<long long> c(b.begin(), b.end());
  long long st = c.size();
  long long mx = c[st - 1];
  long long tx = c[st - 2];
  if (b.size() == 1) {
    for (long long i = 0; i < n; i++) cout << a[0] << endl;
  } else {
    for (long long i = 0; i < n; i++) {
      if (a[i] != mx)
        cout << mx << endl;
      else
        cout << tx << endl;
    }
  }
  return 0;
}
