#include <bits/stdc++.h>
using namespace std;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  vector<int> a(N);
  vector<int> b(N);
  for (int i = 0; i < (int)(N); i++) {
    cin >> a[i];
    b[i] = a[i];
  }
  sort(b.rbegin(), b.rend());
  int max1 = b[0];
  int max2 = b[1];
  if (b[0] == b[1]) {
    for (int i = 0; i < (int)(N); i++) cout << a[0] << endl;
  } else {
    for (int i = 0; i < (int)(N); i++) {
      if (a[i] == b[0])
        cout << b[1] << endl;
      else
        cout << b[0] << endl;
    }
  }
}
