#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

bool distinct(int N, int X, vector<int> A) {
    bool is = true;
    int count = 0;
    for (int i = 0; i < N; i++) {
        if (X == A[i]) count ++;
    }
    if (count > 1) is = false;
    return is;
}

int main() {
    int N;
    cin >> N;
    vector<int> A(N);
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }

    int first = 0;
    int second = 0;

    for (int i = 0; i < N; i++) {
        first = max(first, A[i]);
    }

    for (int i = 0; i < N; i++) {
        if (A[i] < first) second = max(second, A[i]);
    }

    vector<bool> DistOrNot(N, false);
    for (int i = 0; i < N; i++) {
        if (distinct(N, A[i], A)) DistOrNot[i] = true;
    }

    for (int i = 0; i < N; i++) {
        if (A[i] == first && DistOrNot[i]) cout << second << endl;
        else cout << first << endl;
    }
    return 0;
}