#include <bits/stdc++.h>
using namespace std;
vector<pair<long long, long long> > prime_factorize(long long n) {
  vector<pair<long long, long long> > res;
  for (long long p = 2; p * p <= n; ++p) {
    if (n % p != 0) continue;
    int num = 0;
    while (n % p == 0) {
      ++num;
      n /= p;
    }
    res.push_back(make_pair(p, num));
  }
  if (n != 1) res.push_back(make_pair(n, 1));
  return res;
}
long long gcd(long long x, long long y) {
  if (y == 0) {
    return x;
  } else {
    return gcd(y, x % y);
  }
}
bool is_prime(long long n) {
  if (n <= 1) return false;
  for (long long p = 2; p * p <= n; ++p) {
    if (n % p == 0) return false;
  }
  return true;
}
const int MOD = 1000000007;
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
int main() {
  int n;
  cin >> n;
  vector<int> A(n);
  vector<int> B(n);
  for (int i = 0; i < (n); i++) {
    cin >> A[i];
    B[i] = A[i];
  }
  sort(A.begin(), A.end());
  reverse(A.begin(), A.end());
  int Max = A[0];
  int sMax = Max;
  for (int i = 1; i < n; i++) {
    if (A[i] != sMax) {
      sMax = A[i];
      break;
    }
  }
  for (int i = 0; i < (n); i++) {
    if (B[i] == Max) {
      cout << sMax << endl;
    } else {
      cout << Max << endl;
    }
  }
  return 0;
}
