#include <bits/stdc++.h>
using namespace std;
int n, a[200005], b[200005];
int main() {
  int ans, num;
  while (scanf("%d", &n) != EOF) {
    ans = 0;
    num = 0;
    for (int i = 0; i < n; ++i) {
      scanf("%d", &a[i]);
      b[i] = a[i];
      if (ans < a[i]) {
        ans = a[i];
        num = 0;
      } else if (ans == a[i]) {
        num++;
      }
    }
    if (num > 0)
      for (int i = 0; i < n; ++i) printf("%d\n", ans);
    else {
      sort(b, b + n);
      for (int i = 0; i < n; ++i) {
        if (ans == a[i])
          printf("%d\n", b[n - 2]);
        else
          printf("%d", ans);
      }
    }
  }
  return 0;
}
