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