#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
  if (a % b == 0) {
    return (b);
  } else {
    return (gcd(b, a % b));
  }
}
long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
int kan_hyaku(int n) {
  int kurai = 0;
  for (int i = 0; i < 3; i++) {
    kurai = n % 10;
    n /= 10;
  }
  return kurai;
}
int kan_ju(int n) {
  int kurai = 0;
  for (int i = 0; i < 2; i++) {
    kurai = n % 10;
    n /= 10;
  }
  return kurai;
}
int kan_ichi(int n) {
  int kurai = 0;
  for (int i = 0; i < 1; i++) {
    kurai = n % 10;
    n /= 10;
  }
  return kurai;
}
int keta(int n) {
  int wa = 1;
  while (n > 0) {
    wa *= 10;
    n--;
  }
  return wa;
}
double kan_half(int n) {
  double wa = 1;
  while (n > 0) {
    wa *= 0.5;
    n--;
  }
  return wa;
}
long long facctorialMethod(long long k) {
  long long sum = 1;
  for (long long i = 1; i <= k; ++i) {
    sum = sum % 1000000007 * i % 1000000007;
  }
  return sum;
}
int zorocheck(string s) {
  int count = 0;
  for (int i = 0; i < (int)(s.size()); i++) {
    if (s.at(i) == s.at(0)) count++;
  }
  if (count == s.size()) {
    return 1;
  } else {
    return 0;
  }
}
bool red[100010] = {};
int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < (int)(n); i++) cin >> a.at(i);
  int first = 0;
  for (int i = 0; i < (int)(n); i++) first = max(first, a.at(i));
  int first_count = 0;
  for (int i = 0; i < (int)(n); i++)
    if (first == a.at(i)) first_count++;
  if (first_count >= 2) {
    for (int i = 0; i < (int)(n); i++) cout << first_count << endl;
    return 0;
  } else {
    int second = 0;
    for (int i = 0; i < (int)(n); i++) {
      if (a.at(i) != first) {
        second = max(second, a.at(i));
      }
    }
    for (int i = 0; i < (int)(n); i++) {
      if (a.at(i) == first) {
        cout << second << endl;
      } else {
        cout << first << endl;
      }
    }
  }
}
