#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 99999999999999999
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


#define NUM 200005
int N,M;
int A[NUM],B[NUM];

int main(){

	scanf("%d %d",&N,&M);

	for(int i = 0; i < N; i++){

		scanf("%d",&A[i]);
	}

	for(int i = 0; i < M; i++){

		scanf("%d",&B[i]);
	}

	int index = 0;

	//and検索
	queue<int> AND;

	for(int i = 0; i < N; i++){
		while(index < M && B[index] < A[i])index++;
		if(index == M)break;
		if(B[index] == A[i]){
			AND.push(A[i]);
			index++;
		}
	}

	//or検索
	vector<int> OR;

	for(int i = 0; i < N; i++){
		OR.push_back(A[i]);
	}

	index = 0;
	for(int i = 0; i < M; i++){
		while(index < N && A[index] < B[i])index++;
		if(index == N){
			for(int k = i; k < M; k++){
				OR.push_back(B[k]);
			}
			break;
		}
		if(A[index] == B[i])continue;
		else{
			OR.push_back(B[i]);
		}
	}

	sort(OR.begin(),OR.end());

	printf("%lld %lld\n",AND.size(),OR.size());

	while(!AND.empty()){

		printf("%d\n",AND.front());
		AND.pop();
	}

	for(int i = 0; i < OR.size(); i++){

		printf("%d\n",OR[i]);
	}

	return 0;
}

