#include <bits/stdc++.h>
using namespace std;
void excep_max(int *p, int n, int e) {
  int max = -1;
  for (int i = 0; i < n; i++) {
    if (i != e) {
      if (p[i] > max) {
        max = p[i];
      }
    }
  }
  cout << max << endl;
}
int main() {
  int n;
  int *a = NULL;
  cin >> n;
  a = (int *)malloc(sizeof(int) * n);
  int max = 0;
  int sub_max = -1;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (a[i] >= sub_max) {
      max = a[i];
      sub_max = max;
    }
  }
  for (int i = 0; i < n; i++) {
    if (a[i] == max) {
      cout << sub_max << endl;
    } else {
      cout << max << endl;
    }
  }
  return 0;
}
