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