#include <bits/stdc++.h>
using namespace std;

int main() {
  int N;
  cin >> N;
  int v[N];
  for (int i=0; i<N; ++i) {
    cin >> v[i];
  }
  int c = v;
  sort(c.begin(), c.end()), greater<int>);
  for (int i=0; i<N; ++i) {
    if (v[i] != v[0]) {
      cout << v[0] << endl;
    } else {
      if (v[i] != v[1]) {
        cout << v[1] << endl;
      } else {
        cout << v[0] << endl;
      }
    }
  }
}