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