#include <bits/stdc++.h>
using namespace std;
long long int find_mod(string s) {
  long long int i, x = 0;
  for (i = 0; i < s.length(); i++) x = (x * 10 + s[i] - '0') % 1000000007;
  return x;
}
long XOR(long long int n) {
  switch (n & 3) {
    case 0:
      return n;
    case 1:
      return 1;
    case 2:
      return n + 1;
    case 3:
      return 0;
  }
}
long long int prime[10000001 + 1];
void sieve1() {
  for (int i = 0; i <= 10000001; i++) prime[i] = 1;
  prime[0] = prime[1] = 0;
  for (int p = 2; p * p <= 10000001; p++) {
    if (prime[p] == 1)
      for (int i = p * p; i <= 10000001; i += p) {
        prime[i] = 0;
      }
  }
}
int min_prime_div_of_n[10000001 + 1];
void sieve2() {
  memset(min_prime_div_of_n, 0, sizeof(min_prime_div_of_n));
  min_prime_div_of_n[0] = min_prime_div_of_n[1] = 1;
  for (int i = 2; i * i <= 10000001; i++) {
    if (min_prime_div_of_n[i] == 0) {
      for (int j = i * 2; j < 10000001; j += i) {
        if (min_prime_div_of_n[j] == 0) {
          min_prime_div_of_n[j] = i;
        }
      }
    }
  }
  for (int i = 2; i <= 10000001; i++)
    if (min_prime_div_of_n[i] == 0) min_prime_div_of_n[i] = i;
}
int max_prime_div_of_n[10000001 + 1];
void sieve3() {
  sieve1();
  memset(max_prime_div_of_n, 0, sizeof(max_prime_div_of_n));
  max_prime_div_of_n[0] = max_prime_div_of_n[1] = 1;
  for (int i = 2; i * i <= 10000001; i++) {
    if (max_prime_div_of_n[i] == 0) {
      for (int j = i * 2; j < 10000001; j += i) {
        if (max_prime_div_of_n[j] == 0 || ((j % i) == 0 && prime[i] == 1)) {
          max_prime_div_of_n[j] = i;
        }
      }
    }
  }
  for (int i = 2; i <= 10000001; i++)
    if (max_prime_div_of_n[i] == 0) max_prime_div_of_n[i] = i;
}
bool is_even(long long int n) { return (n % 2 == 0); }
bool is_odd(long long int n) { return (n % 2 == 1); }
long long int sum(long long int n) {
  long long int sum = 0;
  while (n) {
    sum += n % 10;
    n /= 10;
  }
  return sum;
}
bool isPrime(long long int n) {
  if (n <= 1) return false;
  if (n <= 3) return true;
  if (n == 5) return true;
  if ((n % 2 == 0) || (n % 3 == 0) || (n % 5 == 0)) return false;
  for (long long int i = 5; i * i <= n; i += 6)
    if ((n % i == 0) || (n % (i + 2) == 0)) return false;
  return true;
}
long long int reversenum(long long int x) {
  long long int num = 0;
  while (x > 0) {
    num = num * 10 + x % 10;
    x = x / 10;
  }
  return num;
}
bool ispalindrome(string s) {
  string q = s;
  reverse(q.begin(), q.end());
  return (s == q);
}
bool isvowel(char x) {
  return (x == 'a' || x == 'e' || x == 'i' || x == 'o' || x == 'u');
}
long long int sumarr(long long int a[], long long int n) {
  long long int sum = 0;
  for (long long int i = 0; i < n; i++) sum += a[i];
  return sum;
}
long long mul(long long a, long long b) {
  return ((a % 1000000007) * (b % 1000000007)) % 1000000007;
}
long long fastExpo(long long n, long long e) {
  if (e == 0) return 1LL;
  if (e == 1LL) return n % 1000000007;
  if (e & 1) return mul(n, fastExpo(n, e - 1LL));
  long long aux = fastExpo(n, e / 2LL);
  return mul(aux, aux);
}
long long int findmax(long long int a[], long long int x, long long int y) {
  long long int maxi = -1;
  for (long long int i = x; i <= y; i++) {
    maxi = max(maxi, a[i]);
  }
  return maxi;
}
int main() {
  long long int t;
  long long int n, q;
  cin >> n;
  long long int a[n];
  for (long long int i = 0; i < n; i++) scanf("%lli", &a[i]);
  ;
  ;
  long long int maxi = *max_element(a, a + n);
  long long int ind1, ind2 = 0;
  for (long long int i = 0; i < n; i++) {
    if (maxi == a[i]) {
      ind1 = i;
      break;
    }
  }
  long long int max2 = -1;
  for (long long int i = 0; i < n; i++) {
    if (max2 <= a[i]) {
      if (max2 <= maxi && i != ind1) {
        ind2 = i;
        max2 = a[i];
      }
    }
  }
  for (long long int i = 0; i < n; i++) {
    if (a[i] == maxi)
      cout << a[ind2] << endl;
    else
      cout << a[ind1] << endl;
  }
  return 0;
}
