#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <limits>
#include <cmath>
#include <cassert>
#include <set>

using namespace std;
using ll = long long;

const int INF = 1<<30;
const int MOD = (int)1e9 + 7;
const int MAX_N = (int)1e5 + 5;
#define debug(x) cout << #x << ": " << x << endl

signed main(void)
{
    cin.tie(0);
    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.insert(x);
    }
    for(int i = 0; i < m; i++)
    {
        int x; cin >> x;
        b.insert(x);
    }
    set<int> s, t;
    for(auto x : a)
    {
        if(b.count(x)) s.insert(x);
        t.insert(x);
    }
    for(auto x : b) t.insert(x);
    cout << s.size() << " " << t.size() << endl;
    for(auto x : s) cout << x << endl;
    for(auto x : t) cout << x << endl;
    return 0;
}


