#include <bits/stdc++.h>
using namespace std;
const int M = 1e9 + 7;
const double pyi = 3.14159265358979323846;
bool vis[100005];
int main() {
  int n;
  cin >> n;
  int arr[n];
  for (int i = 0; i < n; i++) cin >> arr[i];
  int mx = arr[0], mxcnt = 0;
  int mx2 = arr[0];
  for (long long i = 0; i < n; i++) {
    if (arr[i] >= mx) {
      mx2 = mx;
      mx = arr[i];
    } else if (arr[i] >= mx2) {
      mx2 = arr[i];
    }
  }
  for (long long i = 0; i < n; i++) {
    if (arr[i] == mx) mxcnt++;
  }
  for (long long i = 0; i < n; i++) {
    if (mxcnt > 1) {
      cout << (mx) << "\n";
    } else {
      if (arr[i] != mx)
        cout << (mx) << "\n";
      else
        cout << (mx2) << "\n";
    }
  }
  return (0);
}
