#include <bits/stdc++.h>
using namespace std;
int main() {
  long int n, a[200000], max = 0, max1 = 0, i, j = 0, t[200000];
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> a[i];
    if (a[i] > max) {
      max = a[i];
    }
  }
  for (i = 0; i < n; i++) {
    if (max1 < a[i] && max1 < max) {
      max1 = a[i];
    }
  }
  for (i = 0; i < n; i++) {
    if (max == a[i]) {
      t[j] = i;
      j++;
    }
  }
  if (j >= 2) {
    for (i = 0; i < n; i++) {
      cout << max << endl;
    }
  } else {
    for (i = 0; i < n; i++) {
      if (i != t[0]) {
        cout << max << endl;
      } else {
        cout << max1 << endl;
      }
    }
  }
  return 0;
}
