#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; (i) < (n); ++ (i))
#define loop(i,a,n) for (int i = (a); (i) < (n); ++ (i))
#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF (int)1e9
#define MOD 0
//#define int ll
using namespace std;
typedef vector<long long> vl;

signed main() {
  int n,f;
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n;
  vector<pair<int, int>> a(n);
  vector<int> ans(n);
  int ans = 0
  rep(i,n) {
    cin >> f;
    a[i] = make_pair(f,i);
  }
  sort(a.begin(), a.end(), greater<int>());
  rep(i,n) {
    if(i != a[0].second) {
      cout << a[0].first << endl;
    } else {
      cout << a[1].first << endl;
    }
  }
}