#include <bits/stdc++.h>;

using namespace std;
using vi = vector<int>;
using vll = vector<long long>;
using vii = vector<vector<int>>;
using ll = long long;
using uii = unordered_map<int, int>;
using ui = unordered_set<int>;


#define MOD 1000000007
#define INF 1e9
#define FOR(a, b, c) for (int a = b; a < c; ++a)
#define FORF(a, b, c) for (int a = b; a <= c; ++a)
#define FORB(a, b, c) for (int a = b; a >= c; --a)
#define sc second
#define fr first




void solve() {
    int n;
    cin >> n;
    unordered_map<int ,int> e;
    unordered_map<int, vi> r;
    FOR(i,0,n){
        int x;
        cin >> x;
        e[x]++;
    }
    for (auto x: e){
        if (x.second >= 3){
            r[3].push_back(x.first); 
            continue;
        } 
        r[x.second].push_back(x.first);
    }
    sort(r[1].begin(), r[1].end());
    sort(r[2].begin(), r[2].end());
    sort(r[3].begin(), r[3].end());
    vi answer((n+1)/2);
    for (int i =0; i < answer.size(); i+=2){
        answer[i] = r[1][r[1].size() -1];
        r[1].pop_back(); 
    }
    int x = 2;
    for (int i =1; i < answer.size(); i+=2){
        if (x == 2){
            answer[i] = r[x][r[x].size() - 1];
            r[x].pop_back();
            x=3;
        }else{
            answer[i] = r[x][r[x].size() - 1];
            r[x].pop_back();
            x=2;
        }   
    }
    for (int i =0; i < answer.size(); i++){
        cout << answer[i] << " ";
    }
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int t = 1;
    //cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}

