#include <bits/stdc++.h>
using namespace std;
signed main() {
  long long n;
  cin >> n;
  vector<long long> a(n);
  for (long long(i) = 0; (i) < (n); (i)++) {
    cin >> a.at(i);
  }
  if (n == 2) {
    cout << a[1] << endl;
    ;
    cout << a[0] << endl;
    ;
  } else {
    long long maxe = *max_element(a.begin(), a.end());
    long long itr = a.end() - find(a.begin(), a.end(), maxe) - 1;
    if (count(a.begin(), a.end(), maxe) == 1) {
      for (long long(i) = 0; (i) < (n); (i)++) {
        if (i == itr) {
          if (itr == 0) {
            cout << *max_element(a.begin() + 1, a.end()) << endl;
            ;
          } else if (itr == n - 1) {
            cout << *max_element(a.begin(), a.end() - 1) << endl;
            ;
          } else {
            cout << max(*max_element(a.begin(), a.begin() + itr - 1),
                        *max_element(a.begin() + itr + 1, a.end()))
                 << endl;
            ;
          }
        } else {
          cout << maxe << endl;
          ;
        }
      }
    } else {
      for (long long(i) = 0; (i) < (n); (i)++) {
        cout << maxe << endl;
        ;
      }
    }
  }
  return 0;
}
