Go: package main

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

type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	return &Scanner{sc}
}

func (sc *Scanner) NextInt() int {
	sc.sc.Scan()
	i, err := strconv.Atoi(sc.sc.Text())
	if err != nil {
		panic(err)
	}
	return i
}

func main() {
	sc := NewScanner()

	n := sc.NextInt()
	m := sc.NextInt()

	mp := map[int]int{}
	for i := 0; i < n; i++ {
		mp[sc.NextInt()]++
	}
	for i := 0; i < m; i++ {
		mp[sc.NextInt()]++
	}
	var and, or []int
	for k, v := range mp {
		if v >= 1 {
			or = append(or, k)
		}
		if v == 2 {
			and = append(and, k)
		}
	}
	sort.Ints(and)
	sort.Ints(or)
	fmt.Println(len(and), len(or))
	for _, v := range and {
		fmt.Println(v)
	}
	for _, v := range or {
		fmt.Println(v)
	}
}

C++: #include<bits/stdc++.h>

using namespace std;

int main()
{
  int n,m;
  cin>>n>>m;

  vector<int> a;
  vector<int> b;
  int tmp;
  for(int i = 0;i < n+m;++i){
    cin>>tmp;
    if(i < n){
      a.push_back(tmp);
    }
    else{
      b.push_back(tmp);
    }
  }

  vector<int> an;
  set_intersection(a.begin(),a.end(),b.begin(),b.end(),back_inserter(an));
  sort(an.begin(),an.end());

  b.insert(b.end(),a.begin(),a.end());
  sort(b.begin(),b.end());
  b.erase(unique(b.begin(),b.end()),b.end());

  cout<<an.size()<<" "<<b.size()<<endl;
  for(int e : an){
    cout<<e<<endl;
  }
  for(int e : b){
    cout<<e<<endl;
  }

return 0;
}

C++: #define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, m, n) for(int i=(m); i<(n); ++i)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define Cout(x) cout << (x) << endl
#define Cout2(x, y) cout << (x) << " " << (y) << endl
#define dump(x) cerr << #x << " = " << (x) << endl;
typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<vector<int>> VVI;
typedef pair<int, int> PII;
const int inf = 1e9;
const double pi = acos(-1.0);

int main() {
	int n, m; cin >> n >> m;
	VI a(n), b(m);
	rep(i, n)cin >> a[i];
	rep(i, m)cin >> b[i];

	VI ans1, ans2;
	set_intersection(all(a), all(b), inserter(ans1, ans1.end()));
	set_union(all(a), all(b), inserter(ans2, ans2.end()));
	Cout2(sz(ans1), sz(ans2));
	for (auto x : ans1)cout << x << endl;
	for (auto x : ans2)cout << x << endl;
}

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

int main(void){
    int n,m;
    scanf("%d %d",&n,&m);
    int a[n];
    int b[m];
    vector<int> dup,all;
    
    for(int i=0;i<n;i++){
        scanf("%d",&a[i]);
    }
    for(int j=0;j<m;j++){
        scanf("%d",&b[j]);
    }

    int ap=0;
    int bp=0;
    int i=1;
    while(ap!=n or bp!=m){

        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++;
        
        if(a[ap]<b[bp]){
            i = a[ap];
        }else{
            i = b[bp];
        }
    }
    
    printf("%d %d\n",dup.size(),all.size());
    
    for(auto itr = dup.begin(); itr != dup.end(); ++itr) {
        printf("%d\n",*itr);
    }
    for(auto itr = all.begin(); itr != all.end(); ++itr) {
        printf("%d\n",*itr);
    }


    return 0;
}

C++: #include <math.h>
#include <stdlib.h>
#include <string.h>
#include <algorithm>
#include <array>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define loop(i, a, n) for (int i = a; i < (n); i++)
#define all(in) in.begin(), in.end()
#define INF = 1e9;
#define MOD = 1e9 + 7;

int main() {
    int n, m;
    cin >> n >> m;
    vector<int> a(n), b(m);
    rep(i, n) cin >> a[i];
    rep(i, m) cin >> b[i];
    set<int> inter, uni;
    set<int> set_b;
    rep(i, m) set_b.insert(b[i]);
    rep(i, n) {
        if (set_b.count(a[i]) == 1) inter.insert(a[i]);
    }
    rep(i, n) uni.insert(a[i]);
    rep(i, m) uni.insert(b[i]);
    cout << inter.size() << " " << uni.size() << endl;
    for (int x : inter) cout << x << endl;
    for (int x : uni) cout << x << endl;
    return 0;
}

C++: #include<iostream>
#include<map>
#include<vector>
using namespace std;
int main(){
    int n,m;
    cin >> n >> m;
    map<int,int> ma;
    for(int i = 0; i < n; i++){
        int a;
        cin >> a;
        ma[a]++;
    }
    for(int i = 0; i < m; i++){
        int a;
        cin >> a;
        ma[a]++;
    }
    vector<int> ans1,ans2;//and,or
    for(auto itr = ma.begin(); itr != ma.end(); itr++){
        int id = itr->first;
        int cnt = itr->second;
        if(cnt == 2)ans1.push_back(id);
        ans2.push_back(id);
    }
    cout << ans1.size() << " " << ans2.size() << endl;
    for(int i = 0; i < ans1.size(); i++){
        cout << ans1[i] << endl;
    }
    for(int i = 0; i < ans2.size(); i++){
        cout << ans2[i] << endl;
    }
}

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

int main()
{
	ios::sync_with_stdio(false), cin.tie(0);
	int n, m;
	cin >> n >> m;
	vector<int> a(n), b(m);
	set<int> dic;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		dic.insert(a[i]);
	}
	vector<int> an, o = a;
	for (int i = 0; i < m; i++) {
		cin >> b[i];
		if (dic.count(b[i])) an.push_back(b[i]);
		o.push_back(b[i]);
	}
	sort(an.begin(), an.end());
	sort(o.begin(), o.end());
	o.erase(unique(o.begin(), o.end()), o.end());
	printf("%d %d\n", (int)an.size(), (int)o.size());
	for (auto val : an) {
		printf("%d\n", val);
	}
	for (auto val : o) {
		printf("%d\n", val);
	}
	return 0;
}

C++: #include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧  
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     
　　　　／　　　＼　 　 |　|     
　　　 /　　 /￣￣￣￣/　　|  
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿  
　 　　　＼/＿＿＿＿/　（u　⊃  
---------------------------------------------------------------------------------------------------*/












int N, M, A[201010], B[201010];
//---------------------------------------------------------------------------------------------------
void _main() {
    cin >> N >> M;
    rep(i, 0, N) cin >> A[i];
    rep(i, 0, M) cin >> B[i];

    vector<int> ansand, ansor;
    int a = 0, b = 0;
    while (a < N and b < M) {
        if (A[a] == B[b]) {
            ansand.push_back(A[a]);
            ansor.push_back(A[a]);
            a++; b++;
        } else if (A[a] < B[b]) {
            ansor.push_back(A[a]);
            a++;
        } else {
            ansor.push_back(B[b]);
            b++;
        }
    }
    while (a < N) {
        ansor.push_back(A[a]);
        a++;
    }
    while (b < M) {
        ansor.push_back(B[b]);
        b++;
    }

    int A = ansand.size();
    int B = ansor.size();

    printf("%d %d\n", A, B);
    fore(i, ansand) printf("%d\n", i);
    fore(i, ansor) printf("%d\n", i);
}