#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int array[n];
  int data;
  for (int i = 0; i < n; i++) {
    cin >> array[i];
  }
  int first, second;
  for (int i = 0; i < n; i++) {
    if (array[i] >= first) {
      second = first;
      first = array[i];
      data = i;
    }
  }
  for (int i = 0; i < n; i++) {
    if (first == second) {
      cout << first << endl;
    } else {
      if (i == data) {
        cout << second << endl;
      } else {
        cout << first << endl;
      }
    }
  }
  return 0;
}
