#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
template <typename NumType>
NumType calcGCD(NumType a, NumType b) {
  if (a < b) {
    NumType tmp = a;
    a = b;
    b = tmp;
  }
  NumType r = a % b;
  while (r != 0) {
    a = b;
    b = r;
    r = a % b;
  }
  return b;
}
template <typename NumType>
NumType cntDivisor(const NumType& num) {
  NumType cnt = 0;
  for (NumType i = 1; i * i <= num; ++i) {
    if (num % i == 0) {
      cnt++;
      if (i * i != num) cnt++;
    }
  }
  return cnt;
}
template <class T>
T Min(T a, T b) {
  return (a < b) ? a : b;
}
template <class T>
T Max(T a, T b) {
  return (a > b) ? a : b;
}
int main() {
  int32_t N;
  array<int32_t, 20000> A;
  cin >> N;
  for (int32_t i = 0; i < N; i++) cin >> A[i];
  int32_t maxFrom0 = 0;
  int32_t maxFromN = 0;
  array<int32_t, 20000> maxFrom0Arr;
  array<int32_t, 20000> maxFromNArr;
  for (int32_t i = 0; i < N; i++) {
    maxFrom0 = Max(maxFrom0, A[i]);
    maxFrom0Arr[i] = maxFrom0;
  }
  for (int32_t i = N - 1; i >= 0; i--) {
    maxFromN = Max(maxFromN, A[i]);
    maxFromNArr[i] = maxFromN;
  }
  for (int32_t i = 0; i < N; i++) {
    int32_t maxFrom0 = 0;
    if (i - 1 >= 0) {
      maxFrom0 = maxFrom0Arr[i - 1];
    }
    int32_t maxFromN = 0;
    if (i + 1 < N) {
      maxFromN = maxFromNArr[i + 1];
    }
    cout << Max(maxFrom0, maxFromN) << '\n';
  }
  return 0;
}
