#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  int nmax = 0;
  int submax = 0;
  cin >> n;
  vector<int> a;
  vector<bool> index(n);
  for (int i = 0; i < (n); i++) {
    int temp;
    cin >> temp;
    a.push_back(temp);
    nmax = max(nmax, temp);
    if (temp < nmax && temp > submax) submax = temp;
  }
  for (int i = 0; i < (a.size()); i++) {
    if (a[i] == nmax) {
      index[i] = true;
    }
  }
  for (int i = 0; i < (n); i++) {
    if (index[i])
      cout << submax << endl;
    else
      cout << nmax << endl;
  }
  return 0;
}
