#include <bits/stdc++.h>
using namespace std;
bool f(long int n, long int* t, long int length) {
  for (long int i = 0; i < length; i++) {
    if (n == t[i]) {
      return 0;
      break;
    }
  }
  return 1;
}
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++;
    }
  }
  for (i = 0; i < n; i++) {
    if (f(i, t, j)) {
      cout << max << endl;
    } else {
      cout << max1 << endl;
    }
  }
  return 0;
}
