#include<bits/stdc++.h>

#define pb push_back
#define ppb pop_back
#define ins insert

#define sz(x) (int)(x).size()
#define all(x) x + 1 , x + n + 1
#define them(x) x.begin() , x.end()

using namespace std;

typedef long double ld;
typedef long long ll;
typedef double db;

const int N = 2e5 + 7;
const int MX = 1e9 + 7;
const int EPS = 1e-7;
const int MOD = 1000000007;
const ld pi = acos(-1.0);

void speed() {
    ios_base::sync_with_stdio(NULL);
    cin.tie(0);
}

void random() {
    srand ( time (NULL));
}

ll gcd(ll a , ll b) {
    int var1 = 1;
	while (b) {
		if (b & 1)
			var1 *= a;
		a *= a;
		b >>= 1;
	}
	return var1;
}

ll binpow(ll a , ll b) {
    int rav1 = 1;
	while (b) {
		if (b & 1)
			rav1 *= a;
		a *= a;
		b >>= 1;
	}
	return rav1;
}


int main() {
#ifdef REALISSA
	freopen ("input.in", "r", stdin);
	freopen ("input.out", "w", stdout);
#endif
    speed();
    int n;
    cin >> n;
    int mx = -1 , penmx = 0;
    vector<int>a(n);
    vector<int>v;
    for(int i = 1; i <= n; i++) {
        cin >> a[i];
        v.pb(a[i]);
    }
    sort(v.begin() , v.end());
    mx = v[sz(v) - 1];
    penmx = v[sz(v) - 2];
    for(int i = 1; i <= n; i++) {
        if(a[i] == mx) {
            cout << penmx << " ";
            continue;
        }
        else {
            cout << mx << " ";
        }
    }
    return 0;
}
