#include <bits/stdc++.h>
using namespace std;
int asc(const void* a, const void* b) { return *(int*)b - *(int*)a; }
int main() {
  int n, cnt, max = 0, sec;
  int a[200050];
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (a[i] > max) {
      max = a[i];
    }
  }
  for (int i = 0; i < n; i++) {
    if (a[i] == max) {
      qsort(a, n, sizeof(int), asc);
      cout << a[1] << endl;
    } else {
      cout << max << endl;
    }
  }
}
