#include <bits/stdc++.h>
using namespace std;
using namespace std;
long long modval[25];
long long arr[10];
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long n;
  cin >> n;
  long long arr[n], arr1[n], arr2[n];
  for (long long i = 0; i < n; i++) {
    cin >> arr[i];
    arr1[i] = arr[i];
    arr2[i] = arr[i];
  }
  for (long long i = 1; i < n; i++) {
    arr1[i] = max(arr1[i - 1], arr1[i]);
  }
  for (long long i = n - 2; i >= 0; i--) {
    arr2[i] = max(arr2[i + 1], arr2[i]);
  }
  for (long long i = 0; i < n; i++) {
    if (i == 0) {
      cout << arr2[i] << endl;
    } else if (i == (n - 1)) {
      cout << arr1[n - 2] << endl;
    } else {
      cout << max(arr1[i - 1], arr2[i + 1]) << endl;
    }
  }
  return 0;
}
