#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int N;
  cin >> N;
  int a[N];
  int max = 0, second_max = 0;
  int max_num = 1;
  for (int i = 0; i < N; i++) {
    cin >> a[i];
    if (a[i] > max) {
      second_max = max;
      max = a[i];
      max_num = 1;
    } else if (a[i] == max) {
      max_num++;
    }
  }
  for (int i = 0; i < N; i++) {
    if (a[i] == max && max_num > 1) {
      cout << max << endl;
    } else if (a[i] == max && max_num == 1) {
      cout << second_max << endl;
    } else {
      cout << max << endl;
    }
  }
}
