#include <iostream>
#include <vector>
#include <map>
using namespace std;

int main() {
    int n, m;
    cin >> n >> m;
    map<int, int> mp;
    for (int i = 0; i < n; i++) {
        int a;
        cin >> a;
        mp[a]++;
    }
    for (int i = 0; i < m; i++) {
        int b;
        cin >> b;
        mp[b]++;
    }

    vector<int> and_nums;
    vector<int> or_nums;
    int n_and = 0, n_or = 0;
    for (auto it = mp.begin(); it != mp.end(); it++) {
        pair<int, int> item = *it;
        if (item.second) {
            or_nums.push_back(item.first);
            n_or++;
        }
        if (item.second == 2) {
            and_nums.push_back(item.first);
            n_and++;
        }
    }

    cout << n_and << " " << n_or << endl;
    for (int i = 0; i < and_nums.size(); i++)
        cout << and_nums[i] << endl;
    for (int i = 0; i < or_nums.size(); i++)
        cout << or_nums[i] << endl;
    return 0;
}
