#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
int main() {
  int n, a[200001];
  cin >> n;
  int maxl[200001], maxr[200001];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (i == 0)
      maxl[i] = a[i];
    else
      maxl[i] = max(a[i], maxl[i - 1]);
  }
  for (int i = n - 1; i >= 0; i--) {
    if (i == n - 1) {
      maxr[i] = a[i];
    } else {
      maxr[i] = max(a[i], maxr[i + 1]);
    }
  }
  for (int i = 0; i < n; i++) {
    if (i == 0) {
      cout << maxr[i];
    } else if (i == n - 1) {
      cout << maxl[i];
    } else {
      cout << max(maxl[i - 1], maxr[i + 1]);
    }
    cout << endl;
  }
  return 0;
}
