#include <bits/stdc++.h>
using namespace std;
using lli = int64_t;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  int T = 1;
  for (int t = 1; t <= T; t++) {
    int n;
    cin >> n;
    int input[n + 1];
    map<int, int> count;
    int max_number = -1, second_max = -1;
    for (int i = 1; i <= n; i++) {
      cin >> input[i];
      count[input[i]] += 1;
      if (max_number < input[i]) {
        second_max = max_number;
        max_number = input[i];
      }
      if (input[i] < max_number) {
        second_max = input[i];
      }
    }
    if (count[max_number] > 1) {
      second_max = max_number;
    }
    for (int i = 1; i <= n; i++) {
      if (input[i] == max_number) {
        if (count[input[i]] > 1) {
          cout << max_number << "\n";
        } else {
          cout << second_max << "\n";
        }
      } else {
        cout << max_number << "\n";
      }
    }
  }
}
