#include <bits/stdc++.h>
using namespace std;
 
int main(){
    int n;
    cin >> n;
    vector<int> retu(n);
    vector<int> han(n)
    for (int i = 0; i < n; i++) {
        cin >> retu.at(i);
        han.at(i) = retu.at(i);
    }
    int a, b;
    sort(han.begin(), han.end());
    a = han.at(n - 1);
    b = han.at(n - 2);
    for(int i = 0; i < n; i++) {
        if(retu.at(i) != a) {
            cout << a << endl;
        } else {
            cout << b << endl;
        }
    }
}