#include <bits/stdc++.h>
using namespace std;
const int maxn = 55, maxm = 1250000 + 5;
int n, a[maxn], sall, ss, g[maxn][maxm];
bool vis[maxn];
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= 2 * n; i++) scanf("%d", &a[i]), sall += a[i];
  sort(a + 1, a + 1 + 2 * n);
  for (int i = n + 1; i <= 2 * n; i++) ss += a[i];
  int ans = (1 << 30), ansx = 0, ansb = 0;
  g[0][0] = (1 << 30);
  for (int i = 2 * n; i > 1; i--) {
    for (int j = 0; j <= ss; j++)
      if (g[n - 1][j] && max(j + a[1] + a[i], sall - j) < ans)
        ans = max(j + a[1] + a[i], sall - j), ansx = j, ansb = i;
    for (int j = min(n, 2 * n - i + 1); j >= 1; j--)
      for (int k = ss; k >= a[i]; k--)
        if (g[j - 1][k - a[i]] && (!g[j][k])) g[j][k] = i;
  }
  vis[ansb] = 1;
  for (int i = n - 1; i >= 1; i--) {
    vis[g[i][ansx]] = 1;
    ansx -= a[g[i][ansx]];
  }
  for (int i = 1; i <= 2 * n; i++)
    if (vis[i]) printf("%d ", a[i]);
  puts("");
  for (int i = 2 * n; i >= 1; i--)
    if (!vis[i]) printf("%d ", a[i]);
  puts("");
  return 0;
}
