#include <bits/stdc++.h>
using namespace std;
int a[200010];
int main() {
  int n;
  int num = 0, maxn = 0, maxx = 0;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    if (a[i] > maxn) {
      maxn = a[i];
      num = 0;
    }
    if (a[i] == maxn)
      num++;
    else if (a[i] > maxx)
      maxx = a[i];
  }
  for (int i = 1; i <= n; i++) {
    if (a[i] == maxn) {
      if (num > 1)
        printf("%d", maxn);
      else
        printf("%d", maxx);
    } else
      printf("%d", maxn);
    printf("\n");
  }
  return 0;
}
