#include <bits/stdc++.h>
using namespace std;
int main() {
  int a[200005] = {}, n, max1 = -1, max2 = -1, k = 0, x;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> x;
    a[i] = x;
    if (x > max1) {
      max1 = x;
      k = 1;
    } else {
      if (max1 == x) {
        k++;
      } else {
        if (x > max2) {
          max2 = x;
        }
      }
    }
  }
  if (k > 1) {
    for (int i = 1; i <= n; i++) {
      cout << max1 << endl;
    }
  } else {
    for (int i = 1; i <= n; i++) {
      if (a[i] != max1) {
        cout << max1 << endl;
      } else {
        cout << max2 << endl;
      }
    }
  }
  return 0;
}
