#include <bits/stdc++.h>
using namespace std;
template <typename Arg1>
void ZZ(const char* name, Arg1&& arg1) {
  std::cerr << name << " = " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void ZZ(const char* names, Arg1&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ',');
  std::cerr.write(names, comma - names) << " = " << arg1;
  ZZ(comma, args...);
}
const long long SZ = 1e5 + 5;
long long n, m1, m2;
long long a[2 * SZ];
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  ;
  cin >> n;
  m1 = -1, m2 = -1;
  for (long long i = 0; i < n; i++) {
    cin >> a[i];
    m1 = max(m1, a[i]);
  }
  for (long long i = 0; i < n; i++) {
    if (m2 < a[i] && a[i] != m1) {
      m2 = a[i];
    }
  }
  for (long long i = 0; i < n; i++) {
    if (a[i] == m1) {
      cout << m2 << '\n';
    } else {
      cout << m1 << '\n';
    }
  }
  return 0;
}
