#include<bits/stdc++.h>
#define all(a) a.begin(), a.end()
#define pb push_back
using namespace std;
using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using pii = pair<int, int>;

const int inf = 1e9;

vi solve(vi a) {
	int n = a.size();
	
	unordered_map<int, vi> inds;
	for (int i=0; i<n; i++) {
		inds[a[i]].pb(i);
	}
	
	sort(all(a));
	
	ll A = 0, B = 0;
	int left = 0, right = n - 1;
	vi ans(n);
	for (int i=n-1; i>=0; i--) {
		if (A < B) {
			ans[left++] = inds[a[i]].back();
			A += a[i];
		}
		else {
			ans[right--] = inds[a[i]].back();
			B += a[i];
		}
		inds[a[i]].pop_back();
	}
	
	return ans;
}


int main() {
	int n;
	cin >> n;
	vi a(n);
	for (int i=0; i<n; i++) cin >> a[i];
	
	vi ans = solve(a);
	
	for (int d : ans) cout << d << ' ';
	cout << endl;
	for (int d : ans) cout << a[d] << ' ';
	
	return 0;
}

/*
9
5 6 6 3 1 1 4 4 3

8
2 2 3 2 3 2 2 3
*/