#include <bits/stdc++.h>
using namespace std;
const long long int MOD = 1e9 + 7;
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int n;
  cin >> n;
  long long int a[n];
  long long int b[n];
  for (long long int i = 0; i < n; i++) {
    cin >> a[i];
    b[i] = a[i];
  }
  sort(b, b + n);
  long long int first = b[n - 1];
  long long int second = b[n - 1];
  for (long long int i = n - 2; i >= 0; i--) {
    if (b[i] != first) {
      second = b[i];
      break;
    }
  }
  for (long long int i = 0; i < n; i++) {
    if (a[i] == first) {
      cout << second << "\n";
    } else {
      cout << first << "\n";
    }
  }
  return 0;
}
