#include "bits/stdc++.h"
#include<vector>
#include<iostream>
#include<queue>
#include<algorithm>
#include<map>
#include<set>
#include<iomanip>
#include<assert.h>
#include<unordered_map>
#include<unordered_set>
#include<string>
#include<stack>
#include<complex>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
template<class T>
using Table = vector<vector<T>>;
const ld eps=1e-9;
	
#define WHATS(var)//cout<<__LINE__<<' '<<#var<<"="<<var<<endl;
	
template<class S, class T> ostream& operator <<(ostream &os, const pair<S, T> v){
	os << "( " << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator <<(ostream &os, const vector<T> &v){
	for(int i = 0; i < v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator <<(ostream &os, const vector<vector<T>> &v){
	for(int i = 0; i < v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}
template<class T> ostream& operator <<(ostream &os, const vector<set<T>> &v){
	for(int i = 0; i < v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}
template<class T> ostream& operator <<(ostream &os, const set<T> &v){
	int i=0;
	for(auto it:v){
		if(i > 0){os << ' ';}
		os << it;
		i++;
	} 
	return os;
}


	
int main() {
	ios::sync_with_stdio(false);
	int N,M;cin>>N>>M;
	set<int>a,b;
	for(int i=0;i<N;++i){
		int x;cin>>x;a.emplace(x);
	}
	for(int i=0;i<M;++i){
		int x;cin>>x;b.emplace(x);
	}
	set<int>c(a);
	for(auto k:b){
		c.emplace(k);
	}
	set<int>d;
	for(auto k:b){
		if(a.find(k)!=a.end())d.emplace(k);
	}
	swap(c,d);
	cout<<c.size()<<' '<<d.size()<<endl;
	for(auto x:c)cout<<x<<endl;
	for(auto x:d)cout<<x<<endl;
	
	return 0;	
}
