#include <bits/stdc++.h>
using namespace std;
const long long N = 2e5 + 100;
long long s[N], s1[N];
int main() {
  long long n;
  while (~scanf("%lld", &n)) {
    for (int i = 0; i < n; i++) {
      scanf("%lld", &s[i]);
      s1[i] = i;
    }
    sort(s, s + n);
    long long Max = s[n - 1], MAX = s[n - 2], sum;
    if (Max == MAX)
      sum = 2;
    else
      sum = 1;
    for (int i = 0; i < n; i++) {
      if (sum == 2)
        printf("%lld\n", Max);
      else {
        if (s1[i] != Max)
          printf("%lld\n", Max);
        else
          printf("%lld\n", MAX);
      }
    }
  }
  return 0;
}
