#include <bits/stdc++.h>
using namespace std;
int a[200005], n;
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) cin >> a[i];
  int m = 0, b = 0;
  for (int i = 0; i < n; i++) {
    m = max(m, a[i]);
  }
  for (int i = 0; i < n; i++) {
    if (a[i] != m) b = max(b, a[i]);
  }
  for (int i = 0; i < n; i++) {
    if (a[i] <= m)
      cout << m << "\n";
    else
      cout << b << "\n";
  }
  return 0;
}
