#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);
  int max = *max_element(a.begin(), a.end());
  int tmp;
  for (int i = 0; i < (n); i++) {
    tmp = a.at(i);
    if (tmp < max) {
      cout << max << endl;
      continue;
    }
    a.at(i) = 0;
    cout << *max_element(a.begin(), a.end()) << endl;
    a.at(i) = tmp;
  }
  return 0;
}
