#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include "algo/debug.h"
#else
#define debug(...) 42
#endif

//Even if we don't end up together, just know I always wished it was you.

#define pb push_back
#define ll long long
#define  all(x) x.begin(), x.end()
#define bp __builtin_popcountll
#define sqr(x) ((llong)sqrt (x))
#define b_ctz __builtin_ctzll
#define b_clz __builtin_clzll

#define DestroyLonely ios_base::sync_with_stdio(0), cin.tie (0), cout.tie (0)

typedef long long llong;
typedef long double ldouble;
typedef unsigned long long ullong;

typedef vector <int> vi;
typedef vector <vector <llong> > matrix;

typedef pair <llong, llong> pll;
typedef pair <int, int> pii;

typedef map <int, int> mii;

typedef set <int> si;

const int mxn = 1e6 + 1;
const llong mnn = 1e3 + 1;
const llong mod = 1e9 + 7;
const int inf = 1e9;
const llong linf = 1e18;
const llong magic = 1000;
const ldouble eps = 1e-9;
const ldouble pi = 3.141592653589;
const string TIME = "25/27";

inline llong log2 (llong x) {return 64 - b_clz (x) - 1;};
inline llong __lcm (llong a, llong b) {return a / __gcd (a, b) * b;}

bool used[mxn];
const int N = 2e5; 
int d[N + 500], k, h, cnt, a[N + 89]; 
int n; 
set<int> s; 
pair<int,int>v[mxn];
int main(){ 
    k = 1;
    while(h <= N){
        h += k;
        if(h <= N){
            d[h] = k;
            cnt++;
        }
        k *= 2;
    }
    cin >> n;
    for(int i = 1; i <= n; i++) { 
        cin >> a[i];
        s.insert(a[i]);
    }
    if(s.size() != d[n]){
        cout << -1;
        return 0;
    }
    else{
        int j = 0;
        sort(a + 1, a + n + 1);
        for(int i = 1; i <= n; i++){
            if(used[a[i]] == false){
                used[a[i]] = true; 
                j++;
            }
            v[j].first++;
            v[j].second = a[i];
        }
        sort(v + 1, v + s.size() + 1);
        for(int i = 1; i <= s.size() / 2; i++){
            cout << v[s.size() - i + 1].second << ' ' << v[i].second << ' ';
        }
        cout << endl;
        for(int i = 1; i <= s.size(); i++){
            cout << v[i].second << ' ';
        }
    }
}