#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
const long long INF = 1e+14;
const long double eps = 1e-8;
const long double pi = acos(-1.0);
void Yes() {
  cout << "Yes" << endl;
  exit(0);
}
void No() {
  cout << "No" << endl;
  exit(0);
}
int main() {
  long long N;
  cin >> N;
  vector<long long> A(200010);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  vector<long long> B(200010);
  for (int i = 0; i < N; i++) {
    B[i] = A[i];
  }
  sort(B.begin(), B.end());
  reverse(B.begin(), B.end());
  long long ma = B[0];
  long long m2a = 0;
  for (int i = 0; i < N; i++) {
    if (A[i] != ma)
      cout << ma << endl;
    else {
      for (int j = 0; j < N; j++) {
        if (B[j] == ma)
          continue;
        else {
          m2a = B[j];
          break;
        }
      }
      cout << m2a << endl;
    }
  }
}
