#include <bits/stdc++.h>
using namespace std;
int n, m, d;
int i, j, k;
void solve() {
  cin >> n;
  vector<int> data(n);
  for (i = 0; i < n; ++i) cin >> data[i];
  auto largest = max_element(data.begin(), data.end());
  auto secondLargest = max_element(
      data.begin(), data.end(),
      [&largest](int &a, int &b) { return ((b != (*largest)) && (a < b)); });
  for (i = 0; i < n; ++i) {
    if (i == largest - data.begin()) {
      cout << *secondLargest << endl;
    } else {
      cout << *largest << endl;
    }
  }
  return;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  solve();
  return 0;
}
