Go: package main

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

// I/O
type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextFloat() float64 {
	f, e := strconv.ParseFloat(s.nextStr(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *Scanner) nextRuneSlice() []rune {
	return []rune(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func (s *Scanner) nextFloatSlice(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextFloat()
	}
	return res
}

// Arithmetic
func max(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m < i {
			m = i
		}
	}
	return m
}

func min(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m > i {
			m = i
		}
	}
	return m
}

func abs(x int) int {
	if x > 0 {
		return x
	}
	return -x
}

func pow(x, y int) int {
	res := 1
	for i := 0; i < y; i++ {
		res *= x
	}
	return res
}

// Sort
type Val struct {
	id, num int
}
type ByNum []Val

func (a ByNum) Len() int           { return len(a) }
func (a ByNum) Less(i, j int) bool { return a[i].num < a[j].num }
func (a ByNum) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }

func main() {
	sc := NewScanner()
	wtr := bufio.NewWriter(os.Stdout)
	N, M := sc.nextInt(), sc.nextInt()
	A := sc.nextIntSlice(N)
	B := sc.nextIntSlice(M)
	And := []int{}
	Or := []int{}
	setOr := make(map[int]bool)
	for _, a := range A {
		setOr[a] = true
	}
	for _, b := range B {
		if setOr[b] {
			And = append(And, b)
		}
		setOr[b] = true
	}
	for k, _ := range setOr {
		Or = append(Or, k)
	}
	sort.Ints(Or)
	sort.Ints(And)

	fmt.Fprintln(wtr, len(And), len(Or))
	for _, v := range And {
		fmt.Fprintln(wtr, v)
	}
	for _, v := range Or {
		fmt.Fprintln(wtr, v)
	}
	wtr.Flush()
}

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;
}