#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  int max = 0;
  int s_max = 0;
  bool max_f = false;
  vector<int> num;
  cin >> n;
  for (int i = 0; i < n; i++) {
    int inp;
    cin >> inp;
    num.push_back(inp);
    if (inp > s_max) {
      if (inp > max) {
        max = inp;
        max_f = false;
      } else if (inp == max) {
        max_f = true;
      } else {
        s_max = inp;
      }
    }
  }
  if (max_f) {
    for (int i = 0; i < n; i++) {
      cout << max << endl;
    }
  } else {
    for (int i = 0; i < n; i++) {
      if (num.at(i) == max) {
        cout << s_max << endl;
      } else {
        cout << max << endl;
      }
    }
  }
  return 0;
}
