#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> vec(n, 0);
  set<int> s;
  for (int i = 0; i < n; ++i) {
    cin >> vec[i];
    s.insert(vec[i]);
  }
  set<int>::reverse_iterator rit = s.rbegin();
  int r = *rit;
  int p = r;
  if (s.size() != 1) {
    rit--;
    p = *rit;
  }
  for (int i = 0; i < n; ++i) {
    if (vec[i] == r)
      cout << p << endl;
    else
      cout << r << endl;
  }
  return 0;
}
