#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  int num1 = 0;
  int num2 = 0;
  int count = 0;
  vector<int> max_pos;
  max_pos.push_back(0);
  for (int i = 0; i < N; i++) {
    int a;
    cin >> a;
    if (a > num1) {
      num1 = a;
      max_pos.erase(max_pos.begin() + 1, max_pos.end());
      max_pos[0] = i;
    } else if (a == num1) {
      max_pos.push_back(i);
    } else if (a > num2) {
      num2 = a;
    }
  }
  int d = 0;
  for (int i = 0; i < N; i++) {
    if (i == max_pos[d]) {
      if (max_pos.size() > 1) {
        cout << num1 << endl;
        d++;
      } else {
        cout << num2 << endl;
      }
    } else {
      cout << num1 << endl;
    }
  }
  return 0;
}
