#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  vector<int> a_tmp(n);
  int max_index = 0;
  int max = 0;
  int second_max = 0;
  int max_cnt = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (a[i] > max) {
      max_index = i;
      second_max = max;
      max = a[i];
    } else if (a[i] == max) {
      max_cnt++;
    } else if (a[i] > second_max) {
      second_max = a[i];
    }
  }
  for (int i = 0; i < n; i++) {
    if (max_cnt >= 1) {
      cout << max << endl;
    } else if (i == max_index) {
      cout << second_max << endl;
    } else {
      cout << max << endl;
    }
  }
  return 0;
}
