#include <bits/stdc++.h>
using namespace std;
long long power(long long b, long long n) {
  if (n == 0)
    return 1;
  else if (n % 2)
    return b * power(b, n / 2) * power(b, n / 2);
  else
    return power(b, n / 2) * power(b, n / 2);
}
long double root(long long n, long long r) {
  long double dif = 0.0001;
  long double guess = n / 2.0;
  while (abs(pow(guess, r) - n) >= dif) {
    long double temp = pow(guess, r) - n;
    long double tmp = r * pow(guess, r - 1);
    guess -= temp / tmp;
  }
  return guess;
}
void fileio() {}
map<char, int> m;
int solve() {
  long long n;
  scanf("%I64d", &n);
  vector<long long> v;
  pair<long long, long long> p;
  vector<pair<long long, long long> > v1;
  for (long long i = long long(0); i < long long(n); i++) {
    long long x;
    scanf("%I64d", &x);
    v.push_back(x);
    p.first = x;
    p.second = i;
    v1.push_back(p);
  }
  sort((v1).rbegin(), (v1).rend());
  long long a, b, i, j;
  a = v1[0].first;
  b = v1[1].first;
  i = v1[0].second;
  j = v1[1].second;
  for (long long k = long long(0); k < long long(n); k++) {
    if (k == i)
      printf("%I64d", long long(b));
    else
      printf("%I64d", long long(a));
    printf(" ");
  }
  return 0;
}
int main() { solve(); }
