#include <bits/stdc++.h>
const int INF = 1e6;
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
using uld = unsigned long long;
using P = pair<int, int>;
const ll mod = 1e9 + 7;
const int dx[4] = {0, 1, 0, -1};
const int dy[4] = {1, 0, -1, 0};
template <class T>
inline bool chmax(T& a, T& b) {
  if (a < b) {
    a = b;
    return true;
  } else
    return false;
}
template <class T>
inline bool chmin(T& a, T& b) {
  if (a > b) {
    a = b;
    return true;
  } else
    return false;
}
int main() {
  int n;
  cin >> n;
  vector<P> num(n);
  for (int i = 0; i < n; i++) {
    int k;
    cin >> k;
    num[i] = make_pair(k, i);
  }
  int ans = num[1].second;
  sort(num.begin(), num.end());
  reverse(num.begin(), num.end());
  if (num[0] == num[1]) {
    for (int i = 0; i < n; i++) {
      cout << num[0].first << endl;
    }
  } else {
    for (int i = 0; i < n; i++) {
      if (i == ans)
        cout << num[1].first << endl;
      else
        cout << num[0].first << endl;
    }
  }
}
