#include <bits/stdc++.h>
using namespace std;
int const N = 2e5 + 2, MOD = 1e9 + 7;
int n;
vector<pair<int, int>> v1, v2;
void solve() {
  for (int i = 0; i < (int)(n); ++i) {
    int ck1 = v1[0].second;
    int ck2 = v2[i].second;
    if (ck1 == ck2)
      cout << v1[0].first << endl;
    else
      cout << v1[1].first << endl;
  }
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> n;
  for (int i = 0; i < (int)(n); ++i) {
    int x;
    cin >> x;
    v1.push_back({x, i});
    v2.push_back({x, i});
  }
  sort(v1.rbegin(), v1.rend());
  solve();
}
