#include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
using namespace std;

void print() { std::cout << std::endl; }

template <class Head, class... Tail> void print(Head &&head, Tail &&... tail) {
    std::cout << head;
    if(sizeof...(tail) != 0)
        std::cout << " ";
    print(std::forward<Tail>(tail)...);
}

template <class T> void print(std::vector<T> &vec) {
    for(auto &a : vec) {
        std::cout << a;
        if(&a != &vec.back())
            std::cout << " ";
    }
    std::cout << std::endl;
}

template <class T> void print(std::vector<std::vector<T>> &df) {
    for(auto &vec : df) {
        print(vec);
    }
}

int main() {
    int n;
    cin >> n;

    vector<int> a(n);
    for(int i = 0; i < n; i++) {
        cin >> a[i];
    }

    std::vector<int> acopy = a;
    boost::sort(acopy);
    int max = acopy.back();
    int nextMax = *(acopy.end() - 1);

    for(int i = 0; i < n; i++) {
        if(a[i] == max) {
            print(nextMax);
        } else {
            print(max);
        }
    }

    return 0;
}