#include <bits/stdc++.h>
using namespace std;
int inf = 100000000;
int main() {
  int n;
  cin >> n;
  vector<pair<int, int> > vec(n);
  for (int i = 0; i < n; i++) {
    cin >> vec[i].first;
    vec[i].second = i;
  }
  sort(vec.begin(), vec.end());
  reverse(vec.begin(), vec.end());
  for (int i = 0; i < n; i++) {
    if (i == vec[i].second)
      cout << vec[1].first << endl;
    else
      cout << vec[0].first << endl;
  }
}
