#include <bits/stdc++.h>
using namespace std;
 
int main () {
    int N;
    cin >> N;
    vector<int> A(N), B;
    for (int &a : A) cin >> a;
    B = A;
    sort(B.rbegin(), B.rend());
    int mx = *max_element(B.begin(), B.end());
    for (int a : A) cout << ((a != mx) ? mx : B.at(1)) << "\n";
}