#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e6 + 7;
int a[maxn];
int main() {
  int N;
  scanf("%d", &N);
  for (int i = 0; i < N; i++) {
    scanf("%d", a + i);
  }
  int _max = a[0];
  int _2max = a[0];
  int count_max = 0;
  for (int i = 1; i < N; i++) {
    if (a[i] > _max)
      _max = a[i];
    else if (a[i] == _max)
      count_max++;
    else {
      if (a[i] > _2max) _2max = a[i];
    }
  }
  for (int i = 0; i < N; i++) {
    if (a[i] == _max) {
      if (count_max == 0)
        printf("%d\n", _2max);
      else
        printf("%d\n", _max);
    } else
      printf("%d\n", _max);
  }
  return 0;
}
