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<bits/stdc++.h>
#define N 1000000010
#define M 200010
using namespace std;

int main(){
  long long int a[M];
  long long int b[M];
  long long int c[M * 2];
  int n,m,Acnt=0,Bcnt=0;
  cin >> n >> m;
  for(int i=0;i<n;i++){
    scanf("%d",&a[i]);
  }
  a[n] = N+10;
  for(int i=0;i<m;i++){
    scanf("%d",&b[i]);
  }
  b[m] = N+11;
  int i=0,j=0,cnt=0;
  while(1){
    if(i == n && j == m)break;
    if(a[i] == b[j]){
      c[cnt++] = a[i];
      c[cnt++] = a[i];
      Acnt++;
      i++;
      j++;
    }else if(a[i] > b[j]){
      Bcnt++;
      c[cnt++] = b[j];
      j++;
    }else{
      Bcnt++;
      c[cnt++] = a[i];
      i++;
    }
  }
  cout << Acnt <<" " << Bcnt + Acnt << endl;
  i=0,j=0;
  /*
  while(1){
    if(i == n && j == m)break;
    if(a[i] == b[j]){
      printf("%d\n",a[i]);
      i++;
      j++;
    }
    if(a[i] > b[j])j++;
    else i++;
  }
  */
  i =0,j=0;
  sort(c,c + cnt);
  for(i=0;i<cnt;i++){
    if(c[i] == c[i+1]){
      printf("%d\n",c[i]);
    }
  }
  /*
  for(i=0;i<cnt;i++){
    printf("%d\n",c[i]);
  }
  */
  for(i=0;i<cnt;i++){
    if(c[i] == c[i+1])continue;
    else{
      printf("%d\n",c[i]);
    }
  }
  return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

//INSERT ABOVE HERE
signed main(){
  Int n,m;
  cin>>n>>m;
  vector<Int> a(n),b(m);
  for(Int i=0;i<n;i++) cin>>a[i];
  for(Int i=0;i<m;i++) cin>>b[i];
  map<Int, Int> cnt;
  for(Int x:a) cnt[x]++;
  for(Int x:b) cnt[x]++;
  map<Int, Int> dup;
  for(auto p:cnt)
    if(p.second==2) dup[p.first]=1;
  cout<<dup.size()<<" "<<cnt.size()<<endl;
  for(auto p:dup) cout<<p.first<<endl;
  for(auto p:cnt) cout<<p.first<<endl;
  return 0;
}

C++: #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);
}

C++: #include<iostream>
#include<string>
#include<iomanip>
#include<cmath>
#include<vector>
#include<algorithm>
#include<map>

using namespace std;

#define int long long
#define rep(i,n) for(int i = 0; i < (n); i++)
#define INF ((long long)1e18)
#define MOD ((int)1e9+7)
#define endl "\n"

#define yn(f) ((f)?"Yes":"No")
#define YN(f) ((f)?"YES":"NO")

#define MAX

signed main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);
	
	map<int,int> mp;
	int a, b, n, m;
	vector<int> c, d;
	
	cin>>n>>m;
	
	
	for(int i = 0; i < n; i++){
		cin>>a;
		mp[a]++;
	}
	for(int i = 0; i < m; i++){
		cin>>a;
		mp[a]++;
	}
	
	for(pair<int,int> t : mp){
		if(t.second == 2) d.push_back(t.first);
		c.push_back(t.first);
	}
	
	cout<<d.size()<<" "<<c.size()<<endl;
	
	for(int i = 0; i < d.size(); i++){
		cout<<d[i]<<endl;
	}
	for(int i = 0; i < c.size(); i++){
		cout<<c[i]<<endl;
	}
	
	return 0;
}

C++: #include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 99999999999999999
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


#define NUM 200005
int N,M;
int A[NUM],B[NUM];

int main(){

	scanf("%d %d",&N,&M);

	for(int i = 0; i < N; i++){

		scanf("%d",&A[i]);
	}

	for(int i = 0; i < M; i++){

		scanf("%d",&B[i]);
	}

	int index = 0;

	//and検索
	queue<int> AND;

	for(int i = 0; i < N; i++){
		while(index < M && B[index] < A[i])index++;
		if(index == M)break;
		if(B[index] == A[i]){
			AND.push(A[i]);
			index++;
		}
	}

	//or検索
	vector<int> OR;

	for(int i = 0; i < N; i++){
		OR.push_back(A[i]);
	}

	index = 0;
	for(int i = 0; i < M; i++){
		while(index < N && A[index] < B[i])index++;
		if(index == N){
			for(int k = i; k < M; k++){
				OR.push_back(B[k]);
			}
			break;
		}
		if(A[index] == B[i])continue;
		else{
			OR.push_back(B[i]);
		}
	}

	sort(OR.begin(),OR.end());

	printf("%lld %lld\n",AND.size(),OR.size());

	while(!AND.empty()){

		printf("%d\n",AND.front());
		AND.pop();
	}

	for(int i = 0; i < OR.size(); i++){

		printf("%d\n",OR[i]);
	}

	return 0;
}

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(ap!=n and a[ap]<b[bp]){
            i = a[ap];
        }else if(bp!=m and a[ap]>=b[bp]){
            i = b[bp];
        }else if(ap==n){
            i = b[bp];
        }else{
            i = a[ap];
        }
    }
    
    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 "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

//#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = 1'000'000'007;
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; }

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N, M; cin >> N >> M;
	map<int, int> mp;
	vector<int> a(N); rep(i, 0, N) {
		cin >> a[i];
	}
	vector<int> b(M); rep(i, 0, M) {
		cin >> b[i];
	}

	rep(i, 0, N)mp[a[i]]++;
	rep(i, 0, M)mp[b[i]]++;

	vector<int> v1;
	vector<int> v2;

	for (auto v : mp) {
		if (v.second == 2)v1.emplace_back(v.first);
		if (v.second >= 1)v2.emplace_back(v.first);
	}

	cout << v1.size() << " " << v2.size() << endl;
	rep(i, 0, v1.size()) { cout << v1[i] << endl; }
	rep(i, 0, v2.size()) { cout << v2[i] << endl; }
	return 0;
}