#include <bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimization("O3")
#pragma GCC optimization("unroll-loops")
using namespace std;
int main() {
  cin.tie(nullptr);
  std::ios::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<int> a(n);
  vector<int> b(n);
  for (long long i = 0; i < (n); i++) {
    cin >> a[i];
    b[i] = a[i];
  }
  sort(a.begin(), a.end());
  int idx = n - 2;
  while (a[idx] == a[n - 1]) idx--;
  for (int i = 0; i < n; i++) {
    if (b[i] == a[n - 1])
      cout << a[idx] << endl;
    else
      cout << a[n - 1] << endl;
  }
}
