#include <bits/stdc++.h>
using namespace std;
const int N = 27, S = 50005;
int n, a[N << 1], ans[2][N], ret, cur = 1e9;
long long g[N][N * S];
bitset<N * S> f[N];
bool vis[N << 1];
inline bool cd(const int& x, const int& y) { return x > y; }
inline void DFS1(const int& nw, const int& lim, const int& cs = 0,
                 const int& sum = 0, const long long& sts = 0) {
  if (nw > lim) return (void)(g[cs][sum] = sts);
  DFS1(nw + 1, lim, cs, sum, sts);
  DFS1(nw + 1, lim, cs + 1, sum + a[nw], sts | (1LL << nw));
}
inline void DFS2(const int& nw, const int& lim, const int& cs = 0,
                 const int& sum = 0, const long long& sts = 0) {
  if (nw > lim) {
    if (cur - sum >= 0 && ~g[n - 1 - cs][cur - sum]) {
      register int i, c = 1;
      for (i = 3; i <= (n << 1); ++i)
        if ((g[n - 1 - cs][cur - sum] >> i) & 1LL)
          ans[0][++c] = a[i], vis[i] = 1;
      for (i = 3; i <= (n << 1); ++i)
        if ((sts >> i) & 1LL) ans[0][++c] = a[i], vis[i] = 1;
      for (c = 0, i = 3; i <= (n << 1); ++i)
        if (!vis[i]) ans[1][++c] = a[i];
      sort(ans[0] + 1, ans[0] + n + 1);
      sort(ans[1] + 1, ans[1] + n + 1, cd);
      for (i = 1; i <= n; ++i) printf("%d%c", ans[0][i], " \n"[i == n]);
      for (i = 1; i <= n; ++i) printf("%d%c", ans[1][i], " \n"[i == n]);
      exit(0);
    }
    return;
  }
  DFS2(nw + 1, lim, cs, sum, sts);
  DFS2(nw + 1, lim, cs + 1, sum + a[nw], sts | (1LL << nw));
}
int main() {
  register int i, j;
  for (scanf("%d", &n), i = 1; i <= n; ++i) scanf("%d", &a[i]);
  for (i = n + 1; i <= (n << 1); ++i) scanf("%d", &a[i]);
  sort(a + 1, a + (n << 1) + 1);
  ans[0][1] = a[1];
  ans[1][n] = a[2];
  for (f[0][0] = 1, i = 3; i <= (n << 1); ++i)
    for (ret += a[i], j = min(n - 1, i - 2); j; --j) f[j] |= (f[j - 1] << a[i]);
  for (i = 0; i <= ret; ++i)
    if (f[n - 1][i])
      if (max(i, ret - i) < cur) cur = max(i, ret - i);
  return memset(g, -1, sizeof(g)), DFS1(3, n + 1), DFS2(n + 2, n << 1), 0;
}
