#include <bits/stdc++.h>
using namespace std;
int n, a[200005];
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) scanf("%d", &a[i]);
  int max = -1, max2t = -1, chk = 0;
  for (int i = 1; i <= n; ++i) {
    if (a[i] > max) {
      max2t = max;
      max = a[i];
    } else if (a[i] == max)
      chk = 1;
    else if (a[i] > max2t)
      max2t = a[i];
  }
  for (int i = 1; i <= n; ++i) {
    if (a[i] != max || (chk))
      cout << max << endl;
    else
      cout << max2t << endl;
  }
  return 0;
}
