#include <bits/stdc++.h>
using namespace std;
int main() {
  long long t, n, m, i, j, k, x = 0, y = 0, z;
  cin >> n;
  long long a[n + 5], b[n + 5];
  vector<long long> c;
  for (i = 1; i <= n; i++) {
    cin >> a[i];
    x = max(a[i], x);
    b[i] = x;
    c.push_back(a[i]);
  }
  sort(c.begin(), c.end());
  z = unique(c.begin(), c.end()) - c.begin();
  for (i = 1; i <= n; i++) {
    if (a[i] == x) {
      if (z == 1) {
        cout << a[i] << endl;
      } else {
        cout << c[z - 2] << endl;
      }
    } else {
      cout << x << endl;
    }
  }
}
