#include <bits/stdc++.h>
using namespace std;
const int maxx = 2e5 + 7;
const int Inf = 1 << 30;
const long long INF = 1ll << 60;
int n;
int a[maxx];
int main() {
  scanf("%d", &n);
  int maxT = 0;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    maxT = max(maxT, a[i]);
  }
  int cnt = 0;
  for (int i = 1; i <= n; i++) {
    if (a[i] == maxT) cnt++;
  }
  if (cnt > 1) {
    for (int i = 1; i <= n; i++) printf("%d\n", maxT);
  } else {
    sort(a + 1, a + n + 1);
    for (int i = 1; i <= n; i++) {
      if (a[i] != maxT)
        printf("%d\n", a[n]);
      else
        printf("%d\n", a[n - 1]);
    }
  }
  return 0;
}
