#include <bits/stdc++.h>
using namespace std;

int main(void){
	int n, m;
	cin >> n >> m;
	vector<int> a(n);
	vector<int> b(m);
	vector<int> ans_and;
	vector<int> ans_or;
	for(int i = 0; i < n; ++i){
		cin >> a[i];
	}
	for(int i = 0; i < m; ++i){
		cin >> b[i];
	}
	int num_a = 0, num_o = 0;
	int i = 0, j = 0;
	while(true){
		if(a[i] == b[j]){
			ans_and.push_back(a[i]);
			ans_or.push_back(a[i]);
			i++; j++;
		}else if(a[i] > b[j]){
			ans_or.push_back(b[j]);
			j++;
		}else{
			ans_or.push_back(a[i]);
			i++;
		}
		if(i == n || j == m) {break;}
	}
	while(i != n){ ans_or.push_back(a[i]); i++;}
	while(j != m){ ans_or.push_back(b[j]); j++;}
	cout << ans_and.size() << " " << ans_or.size() << endl;
	for(auto x : ans_and) cout << x << endl;
	for(auto x : ans_or) cout << x << endl;
	return 0;
}
