#include <bits/stdc++.h>
#pragma GCC optimize("O2")
using namespace std;
int a[200010];
int main() {
  ios::sync_with_stdio(false);
  int n, i, maxv1 = -1, maxv2 = -1;
  bool flag = true;
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> a[i];
    if (i > 0 && a[i] != a[i - 1]) flag = false;
    maxv1 = max(maxv1, a[i]);
  }
  if (flag) {
    for (i = 0; i < n; i++) cout << *a << endl;
    return 0;
  }
  for (i = 0; i < n; i++)
    if (a[i] != maxv1) maxv2 = max(maxv2, a[i]);
  for (i = 0; i < n; i++)
    if (a[i] == maxv1)
      cout << maxv2 << endl;
    else
      cout << maxv1 << endl;
  return 0;
}
