#include <bits/stdc++.h>
using namespace std;
int dx[] = {-1, 0, 1, 0};
int dy[] = {0, -1, 0, 1};
int ddx[] = {-1, 0, 1, 0, -1, 1, -1, 1};
int ddy[] = {0, -1, 0, 1, 1, 1, -1, -1};
int n, maxv, minv, cnt;
int a[100000];
int main() {
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    maxv = max(maxv, a[i]);
  }
  for (int i = 0; i < n; ++i) {
    if (maxv == a[i])
      ++cnt;
    else
      minv = max(minv, a[i]);
  }
  for (int i = 0; i < n; ++i) {
    if (maxv != a[i])
      cout << maxv << endl;
    else if (maxv == a[i]) {
      if (cnt >= 2)
        cout << maxv << endl;
      else
        cout << minv << endl;
    }
  }
  return 0;
}
