#include <bits/stdc++.h>
using namespace std;
int main() {
  int a, c, d = 0, e = 0, g = 0;
  vector<int> b;
  cin >> a;
  for (int i = 0; i < a; i++) {
    cin >> c;
    b.push_back(c);
    if (d < c) d = c;
    if (e < c && d > c) e = c;
    if (g < c) g = c;
  }
  for (int i = 0; i < a; i++) {
    if (b[i] == d) {
      if (d == e) {
        cout << g << endl;
        continue;
      } else
        cout << e << endl;
    } else
      cout << d << endl;
  }
  return 0;
}
