#include <bits/stdc++.h>
using namespace std;
constexpr int INF = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  int a[200010];
  int left[200010] = {};
  int right[200010] = {};
  for (int i = 1; i <= n; ++i) cin >> a[i];
  for (int i = 1; i <= n; ++i) {
    left[i] = max(left[i - 1], a[i]);
    right[i] = max(right[i + 1], a[i]);
  }
  int ans;
  for (int i = 1; i <= n; ++i) {
    ans = max(left[i - 1], right[i + 1]);
    cout << ans << "\n";
  }
  return 0;
}
