/*  -*- coding: utf-8 -*-
 *
 * 2930.cc: 
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 200000;

/* typedef */

/* global variables */

int as[MAX_N], bs[MAX_N];
int ds[MAX_N], os[MAX_N * 2];

/* subroutines */

/* main */

int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; i++) scanf("%d", as + i);
  for (int i = 0; i < m; i++) scanf("%d", bs + i);

  int dn = 0, on = 0;
  int ai = 0, bi = 0;
  while (ai < n && bi < m) {
    if (as[ai] < bs[bi])
      os[on++] = as[ai++];
    else if (as[ai] > bs[bi])
      os[on++] = bs[bi++];
    else
      ds[dn++] = os[on++] = as[ai++], bi++;
  }
  while (ai < n) os[on++] = as[ai++];
  while (bi < m) os[on++] = bs[bi++];

  printf("%d %d\n", dn, on);
  for (int i = 0; i < dn; i++) printf("%d\n", ds[i]);
  for (int i = 0; i < on; i++) printf("%d\n", os[i]);
  return 0;
}

