#include <bits/stdc++.h>
using namespace std;
constexpr long long MOD = long long(1e9) + 7;
constexpr int IINF = INT_MAX;
constexpr long long LLINF = LLONG_MAX;
constexpr int MAX_N = int(1e5) + 5;
constexpr double EPS = 1e-9;
constexpr int di[] = {0, 1, 0, -1}, dj[] = {1, 0, -1, 0};
int main() {
  int n, a[MAX_N], f, s;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (f < a[i]) {
      s = f;
      f = a[i];
    } else if (s < a[i]) {
      s = a[i];
    }
  }
  for (int i = 0; i < n; i++) {
    if (a[i] < f) {
      cout << f << endl;
    } else {
      cout << s << endl;
    }
  }
  return 0;
}
