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

int main() {
    int n, m;
    while (cin >> n >> m) {
        map<int,int> a;
        for (int i = 0; i < n; ++i) {
            int c; cin >> c;
            a[c]++;
        }
        for (int i = 0; i < m; ++i) {
            int c; cin >> c;
            a[c]++;
        }
        vector<int> And, Or;
        for (auto it : a) {
            if (it.second == 2) And.push_back(it.first);
            Or.push_back(it.first);
        }
        cout << And.size() << " " << Or.size() << endl;
        for (auto v : And) cout << v << endl;
        for (auto v : Or) cout << v << endl;
    }
}

