#define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, m, n) for(int i=(m); i<(n); ++i)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define Cout(x) cout << (x) << endl
#define Cout2(x, y) cout << (x) << " " << (y) << endl
#define dump(x) cerr << #x << " = " << (x) << endl;
typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<vector<int>> VVI;
typedef pair<int, int> PII;
const int inf = 1e9;
const double pi = acos(-1.0);

int main() {
	int n, m; cin >> n >> m;
	VI a(n), b(m);
	rep(i, n)cin >> a[i];
	rep(i, m)cin >> b[i];

	VI ans1, ans2;
	set_intersection(all(a), all(b), inserter(ans1, ans1.end()));
	set_union(all(a), all(b), inserter(ans2, ans2.end()));
	Cout2(sz(ans1), sz(ans2));
	for (auto x : ans1)cout << x << endl;
	for (auto x : ans2)cout << x << endl;
}
