#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;

int main() {
  int n;
  cin >> n;
  vector<int> a(n); rep (i, n) cin >> a[i];
  int max_1st, max_2nd;
  if (a[n - 1] > a[n - 2]) {
    max_1st = a[n - 1];
    max_2nd = a[n - 2];
  } else {
    max_1st = a[n - 2];
    max_2nd = a[n - 1];
  }
  rep(i, n - 2) {
    if (a[i] > max_1st) {
      max_2nd = max_1st;
      max_1st = a[i];
    } else if (a[i] > max_2nd) {
      max_2nd = a[i];
    }
  }
  rep(i, n) cout << (a[i] > max_1st) ? max_2nd : max_1st << endl;

//  int ans = n - (int)(n - (float)n / (2 * d + 1)); // 切り上げ
//  cout << ans << endl;

//  vector<int> a(n);
//  rep(i,n) cin >> a[i];
//  ll x2 = 0;
//  rep(i,n) {
//    if (i%2) x2 -= a[i];
//    else x2 += a[i];
//  }
//  vector<int> ans(n);
//  ans[0] = x2/2;
//  rep(i,n-1) {
//    ans[i+1] = a[i]-ans[i];
//  }
//  rep(i,n) ans[i] *= 2;
//  rep(i,n) printf("%d%c", ans[i], i==n-1?'\n':' ');
  return 0;
}
