#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int A[n];
  int max = 0, second = 0;
  int place = 0;
  bool exist;
  for (int i = 0; i < n; i++) {
    A[i] = 0;
  }
  for (int i = 0; i < n; i++) {
    cin >> A[i];
    if (max < A[i]) {
      max = A[i];
      exist = false;
    } else if (max == A[i]) {
      exist = true;
    } else {
      if (second < A[i]) {
        second = A[i];
      }
    }
  }
  for (int i = 0; i < n; i++) {
    if (A[i] == max && exist) {
      cout << max << endl;
    } else if (A[i] == max && !exist) {
      cout << second << endl;
    } else {
      cout << max << endl;
    }
  }
}
