#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);
  }
  long long maxe = *max_element(a.begin(), a.end());
  if (count(a.begin(), a.end(), maxe) > 1) {
    for (long long(i) = 0; (i) < (n); (i)++) {
      cout << maxe << endl;
      ;
    }
  } else {
    for (long long(i) = 0; (i) < (n); (i)++) {
      if (i == a.end() - find(a.begin(), a.end(), maxe) - 1) {
        if (i == 0) {
          cout << *max_element(a.begin() + 1, a.end()) << endl;
          ;
        } else if (i == n - 1) {
          cout << *max_element(a.begin(), a.end() - 1) << endl;
          ;
        } else {
          long long ma, mb;
          ma = *max_element(a.begin(), a.begin() + i - 1);
          mb = *max_element(a.begin() + i + 1, a.end());
          cout << max(ma, mb) << endl;
          ;
        }
      } else {
        cout << maxe << endl;
        ;
      }
    }
  }
  return 0;
}
