#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n;
  cin >> n;
  long long arr[n + 5];
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
  }
  long long mx = arr[0];
  for (int i = 0; i < n; i++) {
    if (mx < arr[i]) mx = arr[i];
  }
  long long cnt = 0;
  for (int i = 0; i < n; i++) {
    if (mx == arr[i]) cnt++;
  }
  if (cnt >= 2) {
    for (int i = 0; i < n; i++) cout << mx << endl;
  } else {
    sort(arr, arr + n);
    for (int i = 1; i <= n; i++) {
      if (arr[i] != mx)
        cout << mx << endl;
      else if (arr[i] == mx)
        cout << arr[1] << endl;
    }
  }
  return 0;
}
