#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
int a[maxn * 2];
int ans[maxn * 2];
struct Node {
  int x, y;
} s[maxn * 2];
int maxpr[maxn];
int maxed[maxn];
int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> a[i];
  for (int i = 1; i <= n; i++) maxpr[i] = max(maxpr[i - 1], a[i]);
  for (int i = n; i >= 1; i--) maxed[i] = max(maxed[i + 1], a[i]);
  for (int i = 1; i <= n; i++) {
    cout << max(maxpr[i - 1], maxed[i + 1]) << endl;
  }
  return 0;
}
