#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
  for (auto v : vec) os << v << ' ';
  os << '\n';
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &pa) {
  os << '(' << pa.first << ',' << pa.second << ')';
  return os;
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << H;
  debug_out(T...);
}
template <class T>
inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
const int INF = (1 << 30) - 1;
const ll LINF = (1LL << 60) - 1;
void solve() {
  int n;
  cin >> n;
  vector<int> A(n);
  int f = 0, m = 0, s = 0;
  for (int i = 0; i < n; i++) {
    cin >> A[i];
    if (m < A[i]) {
      m = A[i];
      f = 0;
    } else if (m == A[i]) {
      f = 1;
    }
    if (m > A[i] && A[i] > s) {
      s = A[i];
    }
  }
  for (int i = 0; i < n; i++) {
    if (f) {
      cout << m << endl;
    } else {
      if (m == A[i]) {
        cout << s << endl;
      } else {
        cout << m << endl;
      }
    }
  }
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  solve();
  return 0;
}
