#include <bits/stdc++.h>
using namespace std;
int arr[200005], n, maxi, lessmaxi;
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
    if (arr[maxi] < arr[i]) maxi = i;
  }
  for (int i = 0; i < n; i++) {
    if (i != maxi && arr[lessmaxi] < arr[i]) lessmaxi = i;
  }
  for (int i = 0; i < n; i++) {
    cout << (i == maxi ? arr[lessmaxi] : arr[maxi]) << endl;
  }
}
