#include <bits/stdc++.h>
using namespace std;
const int N = 300030;
const long long mod = 1e9 + 7;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  int x = 0;
  int y = n - 1;
  int arr[n];
  for (__typeof(n) i = (0) - ((0) > (n)); i != (n) - ((0) > (n));
       i += 1 - 2 * ((0) > (n)))
    cin >> arr[i];
  for (int i = 0; i < n; i++) {
    if (arr[i] > arr[x]) x = i;
  }
  for (int i = 0; i < n; i++) {
    if (arr[i] > arr[y] && i != x) y = i;
  }
  for (int i = 0; i < n; i++) {
    if (i != x)
      cout << arr[x] << "\n";
    else
      cout << arr[y] << "\n";
  }
}
