#include<bits/stdc++.h>

int main(){
    using namespace std;
    size_t n, m;
    scanf("%lu%lu", &n, &m);
    vector<size_t> a(n), b(m), c, d;
    for(auto& i : a)scanf("%lu", &i);
    for(auto& i : b)scanf("%lu", &i);
    set_intersection(begin(a), end(a), begin(b), end(b), back_inserter(c));
    set_union(begin(a), end(a), begin(b), end(b), back_inserter(d));
    printf("%lu %lu\n", c.size(), d.size());
    for(const auto i : c)printf("%lu\n", i);
    for(const auto i : d)printf("%lu\n", i);
}
