#include <bits/stdc++.h>

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define INF  numeric_limits<int>::max()
#define NINF numeric_limits<int>::min()

#define N_MAX 2000000
#define M_MAX 2000000

using namespace std;
using ll = long long;

int n, m;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);

    std::cin >> n >> m;
    set<int> or_s;
    vector<int> and_v;
    REP(i, n) {
        int a;
        std::cin >> a;
        or_s.insert(a);
    }
    REP(i, m) {
        int b;
        std::cin >> b;
        auto itr = or_s.find(b);
        if(itr != or_s.end()) {
            and_v.push_back(b);
        }
        or_s.insert(b);
    }

    std::cout << and_v.size()
              << " "
              << or_s.size() << std::endl;
    REP(i, and_v.size()) {
        std::cout << and_v[i] << std::endl;
    }
    for(auto s : or_s) {
        std::cout << s << std::endl;
    }

    return 0;
}

