#include <iostream>

using namespace std;

int main() {
  int N, a, I, m{0}, m2;
  cin >> N;
  for (int i = 0; i != N; ++i) {
    cin >> a;
    if (m <= a) {
      m2 = m;
      m = a;
      I = i;
    } else if (m2 < a) m2 = a;
  }
  
  for (int i = 0; i != N; i++) {
    cout << (i==I ? m2:m) << endl;
  }
}
