#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
const int INF = 1 << 30;
const int MOD = 2019;
inline void boost() {
  cin.tie(0), cout.tie(0), cin.sync_with_stdio(0), cout.sync_with_stdio(0);
}
int main() {
  boost();
  int n;
  cin >> n;
  vector<int> a(n), b(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    b[i] = a[i];
  }
  sort(b.begin(), b.end());
  for (int i = 0; i < n; i++) {
    if (a[i] != b[n - 1])
      cout << b[n - 1] << "\n";
    else {
      int j = n - 2;
      while (b[j] == b[n - 1] and j > 0) {
        j--;
      }
      cout << b[j] << "\n";
    }
  }
  return 0;
}
