#include<stdio.h>
#include<vector>
#include<algorithm>

#include<iostream>

void input(std::vector<int>&);
void calc(std::vector<int>&);
void output(std::vector<int>);

int main(){
    std::vector<int> in;

    input(in);
    calc(in);
    output(in);

    return 0;
}

void input(std::vector<int>& t_in){
    int size;
    std::cin >> size;
    t_in.resize(size);
    for(auto& t : t_in) std::cin >> t;
}

void calc(std::vector<int>& t_in){
    auto mi = std::max_element(t_in.begin(), t_in.end());
    auto mp = mi - t_in.begin();

    if(mp != 0){
        std::iter_swap(mi, t_in.begin());
    }
    else{
        std::iter_swap(t_in.end() - 1, t_in.end() - 2);
    }
}

void output(std::vector<int> t_in){
    for(auto& t : t_in) std::cout << t << " ";
    std::cout << "\n";
}