#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> vec(n, 0), ans(n, 0);
  for (int i = 0; i < n; ++i) {
    cin >> vec[i];
    ans[i] = vec[i];
  }
  sort(vec.begin(), vec.end());
  int r = vec[n - 1];
  int cnt = n - 1;
  while (cnt >= 0) {
    r = vec[cnt];
    if (r != vec[n - 1]) break;
    cnt--;
  }
  for (int i = 0; i < n; ++i) {
    if (ans[i] == vec[n - 1]) {
      cout << r << endl;
    } else {
      cout << vec[n - 1] << endl;
    }
  }
  return 0;
}
