#include <bits/stdc++.h>
using namespace std;
int n, a[200020];
int maxx1[200020];
int maxx2[200020];
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    maxx1[i] = max(maxx1[i - 1], a[i]);
  }
  for (int i = n; i >= 1; i--) {
    maxx2[i] = max(maxx2[i + 1], a[i]);
  }
  for (int i = 1; i <= n; i++) {
    int ans = max(maxx1[i - 1], maxx2[i + 1]);
    cout << ans << endl;
  }
}
