#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
    int N;
    cin >> N;
    vector<int> A(N);
    for (int& i : A) cin >> i;
    vector<int> B(A);
    partial_sort(B.begin(), B.begin() + 2, B.end(), greater<int>());
    for (int i : A) cout << (i == B[0] ? B[1] : B[0]) << endl;
}