#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n;
  cin >> n;
  int max_val = INT_MIN;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    max_val = max(max_val, a[i]);
  }
  int ctr = -1;
  int pos[(int)2 * (int)1e5];
  int k = 0;
  for (int i = 0; i < n; i++) {
    if (a[i] == max_val) {
      ctr++;
      pos[k++] = i;
    }
  }
  k = 0;
  for (int i = 0; i < n; i++) {
    if (ctr > 0 and i == pos[k++]) {
      cout << max_val << "\n";
    } else if (a[i] != max_val) {
      cout << max_val << "\n";
    } else {
      int sec_max = INT_MIN;
      for (int i = 0; i < n; i++) {
        if (a[i] < max_val and a[i] >= sec_max) {
          sec_max = a[i];
        }
      }
      cout << sec_max << "\n";
    }
  }
  return 0;
}
