#include <bits/stdc++.h>
using namespace std;
void yasser() {
  std::ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
}
long long gcd(long long a, long long b) { return !b ? a : gcd(b, a % b); }
long long lcm(long long a, long long b) { return (a / gcd(a, b)) * b; }
int main() {
  int n;
  cin >> n;
  vector<int> v(n), v1;
  for (int i = 0; i < n; ++i) {
    cin >> v[i];
  }
  v1 = v;
  sort(((v1).begin()), ((v1).end()));
  bool dub = 0;
  if (v1[n - 1] == v1[n - 2]) dub = 1;
  for (int i = 0; i < n; ++i) {
    if (dub) {
      cout << v[i] << "\n";
    } else {
      if (v[i] == *max_element(((v1).begin()), ((v1).end())))
        cout << v1[n - 2] << "\n";
      else
        cout << v1[n - 1] << "\n";
    }
  }
}
