#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) cin >> a.at(i);
  sort(a.begin(), a.end());
  for (int i = 0; i < n; i++) {
    if (a.at(i) == a.at(n - 1))
      cout << a.at(n - 2) << endl;
    else
      cout << a.at(0) << endl;
  }
}
