Go: package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

func main() {
	var n, m int
	fmt.Scan(&n, &m)

	mm := make(map[int]bool)
	am := make(map[int]bool)
	om := make(map[int]bool)

	var sc = bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	for i := 0; i < n; i++ {
		sc.Scan()
		a, _ := strconv.Atoi(sc.Text())
		mm[a] = true
		om[a] = true
	}
	for i := 0; i < m; i++ {
		sc.Scan()
		b, _ := strconv.Atoi(sc.Text())
		if bl, ok := mm[b]; ok && bl {
			am[b] = true
		}
		om[b] = true
	}
	fmt.Printf("%d %d\n", len(am), len(om))
	as := make([]int, 0)
	for k := range am {
		as = append(as, k)
	}
	sort.Sort(sort.IntSlice(as))
	os := make([]int, 0)
	for k := range om {
		os = append(os, k)
	}
	sort.Sort(sort.IntSlice(os))
	for i := range as {
		fmt.Println(as[i])
	}
	for i := range os {
		fmt.Println(os[i])
	}
}

C++: #include <iostream>
#include <vector> 
using namespace std;

int main(void){
    int n,m;
    cin >> n >> m;
    int a[n];
    int b[m];
    vector<int> dup,all;
    
    for(int i=0;i<n;i++){
        cin >> a[i];     
    }
    for(int j=0;j<m;j++){
        cin >> b[j];
    }
    
    int ap=0;
    int bp=0;
    int i=0;
    int a_s=0;
    int b_s=0;
    while(ap!=n or bp!=m){
        i++;
        
        if(a[ap]==i and b[bp]==i){
            a_s++;
            dup.push_back(i);  
        } 
        if(a[ap]==i or b[bp]==i){
            b_s++;
            all.push_back(i);
        }
        

        while(a[ap]<=i and ap!=n) ap++;
        while(b[bp]<=i and bp!=m) bp++;
    }
    
    cout << a_s <<" "<< b_s << endl;
    
    for(auto itr = dup.begin(); itr != dup.end(); ++itr) {
        cout << *itr << endl;
    }
    for(auto itr = all.begin(); itr != all.end(); ++itr) {
        cout << *itr << endl;
    }

    return 0;
}

C++: //↓template↓

#include "bits/stdc++.h"
using namespace std;
#define Would
#define you
#define all(n)  n.begin(),n.end()
const long long INF = 1e18;
const long long MOD = 1e9 + 7;
const double pi = acos(-1);
const int SIZE = 1 << 17;
int dx[] = { 1,0 }, dy[] = { 0,1 }, alp[30];
long long fac[200005], finv[200005], inv[200005];
vector<long long>dij;
struct edge { long long to, cost; };
vector<vector<edge> >G;

long long mod_pow(long long a, long long b) {
	long long res = 1, mul = a;
	for (int i = 0; i < 31; ++i) {
		if (b >> i & 1) {
			res *= mul;
			res %= MOD;
		}
		mul = (mul * mul) % MOD;
	}

	return res;
}

void addedge(int from, int to, int cost) {
	G[from].push_back({ to,cost });
	G[to].push_back({ from,cost });
}

//↑template↑


long long a, b, k[200005], l[200005], mon;
queue<long long>ans;
set<long long>s;
int main() {
	cin >> a >> b;
	for (int i = 0; i < a; ++i) {
		cin >> k[i];
		s.insert(k[i]);
	}

	for (int i = 0; i < b; ++i) {
		cin >> l[i];
		s.insert(l[i]);
	}

	for (int i = 0; i < a; ++i) {
		while (mon < b&&l[mon] < k[i]) { ++mon; }
		if (mon == b) { break; }
		if (l[mon] == k[i]) {
			ans.push(k[i]);
			++mon;
		}
	}

	cout << ans.size() << " " << s.size() << endl;

	while (!ans.empty()) {
		cout << ans.front() << endl;
		ans.pop();
	}
	while (!s.empty()) {
		auto itr = s.begin();
		cout << *itr << endl;
		s.erase(s.begin());
	}
}

C++: #include <bits/stdc++.h>
using namespace std;

#define int long long

signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  int N;
  int H, W;  
  string s;

  cin >> N;

  int M;
  cin >> M;
  
  vector<int> A(N, 0);
  vector<int> B(N, 0);  
  int ans = 0;

  map<int, int> c;
  for ( int i = 0; i < N; i++ ) {
    int a;
    cin >> a;
    c[a]++;
  }
  for ( int i = 0; i < M; i++ ) {
    int a;
    cin >> a;
    c[a]++;
  }

  int ans1 = 0, ans2 = 0;  
  for ( pair<int, int> a : c ) {
    if ( a.second == 2 ) ans1++;    
  }

  for ( pair<int, int> a : c ) {
    if ( a.second >= 1 ) ans2++;    
  }

  cout << ans1 << " " << ans2 << endl;
  for ( pair<int, int> a : c ) {
    if ( a.second == 2 ) cout << a.first << endl; 
  }

  for ( pair<int, int> a : c ) {
    if ( a.second >= 1 ) cout << a.first << endl;
  }
  
  return 0;
}

C++: #include <iostream>
#include <set>
#define int long long
using namespace std;
int n, m, p;
set<int>s, t;
signed main() {
	cin >> n >> m;
	for (int i = 0; i < n; i++) {
		cin >> p;
		s.insert(p);
	}
	for (int j = 0; j < m; j++) {
		cin >> p;
		if (*(s.lower_bound(p)) == p)t.insert(p);
		else s.insert(p);
	}
	cout << t.size() << ' ' << s.size() << endl;
	for (auto i : t)cout << i << endl;
	for (auto i : s)cout << i << endl;
}

C++: #include <iostream>
#include <vector> 
using namespace std;

int main(void){
    int n,m;
    cin >> n >> m;
    int a[n];
    int b[m];
    vector<int> dup,all;
    
    for(int i=0;i<n;i++){
        cin >> a[i];     
    }
    for(int j=0;j<m;j++){
        cin >> b[j];
    }
    
    int ap=0;
    int bp=0;
    int i=0;
    while(ap!=n or bp!=m){
        i++;
        
        if(a[ap]==i and b[bp]==i) dup.push_back(i);
        if(a[ap]==i or b[bp]==i) all.push_back(i);

        while(a[ap]<=i and ap!=n) ap++;
        while(b[bp]<=i and bp!=m) bp++;
    }
    
    cout << dup.size() <<" "<< all.size()  << endl;
    
    for(auto itr = dup.begin(); itr != dup.end(); ++itr) {
        cout << *itr << endl;
    }
    for(auto itr = all.begin(); itr != all.end(); ++itr) {
        cout << *itr << endl;
    }

    return 0;
}

C++: // vvvvvvvvvvvv TEMPLATE vvvvvvvvvvvv
#include <bits/stdc++.h>
using namespace std; using ll = long long; using P = pair<ll, ll>;
const ll linf = 1e18; const double eps = 1e-12, pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define each(i,a) for (auto&& i : a)
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
#define pb push_back
#define eb emplace_back
#define all(a) begin(a),end(a)
#define chmin(x,v) x = min(x, v)
#define chmax(x,v) x = max(x, v)
#define min(x,y) (x < y ? x : y)
#define max(x,y) (x < y ? y : x)
template<typename Head> void out(Head h) { cout << h << endl; } template<typename Head, typename... Tail>void out(Head h, Tail... t) { cout << h << " "; out(t...); }
template<typename T> istream& operator>>(istream& is, vector<T>& v) { each(x,v) is >> x; return is; }
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) { rep(i,v.size()) { if (i) os << " "; os << v[i]; } return os; }
template<typename T> ostream& operator<<(ostream& os, const vector<string>& v) { rep(i,v.size()) { if (i) os << endl; os << v[i]; } return os; }
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) { rep(i,v.size()) { if (i) os << endl; os << v[i]; } return os; }
struct yes_no : std::numpunct<char> { string_type do_truename() const { return "Yes"; } string_type do_falsename() const { return "No"; } };
void solve(); int main() {
  ios::sync_with_stdio(false); cin.tie(0); locale loc(locale(), new yes_no); cout.imbue(loc); cout << fixed << setprecision(10) << boolalpha;
  solve();
}
// ^^^^^^^^^^^^ TEMPLATE ^^^^^^^^^^^^

void solve() {
  ll n, m; cin >> n >> m;
  vector<ll> a(n), b(m); cin >> a >> b;
  set<ll> s(all(b));
  vector<ll> ans1, ans2 = b;
  each(x, a) {
    if (s.count(x)) {
      ans1.pb(x);
    }
    else {
      ans2.pb(x);
    }
  }
  sort(all(ans1));
  sort(all(ans2));
  cout << ans1.size() << " " << ans2.size() << endl;
  each(x, ans1) cout << x << endl;
  each(x, ans2) cout << x << endl;
}