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 <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
int arr[200001], arr2[200001], arr3[400001], reps[200001];

int main()
{
    int n, m, len, s1, s2, idx, idx2;
    scanf("%d %d", &n, &m);

    for (int i = 0; i < n; i++) scanf("%d", &arr[i]);
    for (int i = 0; i < m; i++) scanf("%d", &arr2[i]);

    len = n + m, s1 = s2 = idx = idx2 = 0;
    while (s1 < n && s2 < m) {
        if (arr[s1] == arr2[s2]) { reps[idx2++] = arr[s1]; arr3[idx++] = arr[s1++]; s2++; }
        else if (arr[s1] < arr2[s2]) arr3[idx++] = arr[s1++];
        else if (arr2[s2] < arr[s1]) arr3[idx++] = arr2[s2++];
    }
    if (s1 <= n - 1) while (s1 < n) arr3[idx++] = arr[s1++];
    if (s2 <= m - 1) while (s2 < m) arr3[idx++] = arr2[s2++];
    printf("%d %d\n", idx2, len - idx2);
    for (int i = 0; i < idx2; i++) printf("%d\n", reps[i]);
    for (int i = 0; i < idx; i++) printf("%d\n", arr3[i]);
     return 0;
}

C++: 
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <cstring>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <list>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <unordered_set>
#include <unordered_map>
#include <array>
#include <cassert>
#include <bitset>
using namespace std;
using LL = long long;

int n, m;
set<int>a, b, ors, ands;

int main(void)
{
	cin >> n >> m;
	for (int i = 0; i < n; ++i) {
		int aa; cin >> aa; a.insert(aa);
		ors.insert(aa);
	}
	for (int j = 0; j < m; ++j) {
		int aa; cin >> aa; b.insert(aa);
		ors.insert(aa);
	}
	for (int elm : a) {
		if (b.count(elm)) {
			ands.insert(elm);
		}
	}
	int A = ands.size();
	int B = ors.size();
	cout << A << " " << B << endl;
	for (int elm : ands) {
		cout << elm;
		cout << endl;
	}
	for (int elm : ors) {
		cout << elm;
		cout << endl;
	}
	return 0;
}

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

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

    int a[n];
    for( int i = 0; i < n; i++ )
        cin >> a[i];
    
    int b[m];
    for( int i = 0; i < m; i++ )
        cin >> b[i];

    vector<int> resa, resb;
    
    int i = 0, j = 0;
    while( i < n && j < m )
    {
        if( a[i] == b[j] )
        {
            resa.push_back( a[i] );
            resb.push_back( a[i] );
            i++; j++;
            continue;
        }
        else if( a[i] < b[j] )
        {
            resb.push_back( a[i] );
            i++;
        }
        else
        {
            resb.push_back( b[j] );
            j++;
        }
    }

    while( i < n )
        resb.push_back( a[i++] );
    while( j < m )
        resb.push_back( b[j++] );

    cout << resa.size() << " " << resb.size() << endl;
    
    for( int k = 0; k < resa.size(); k++ )
        cout << resa[k] << endl;
    
    for( int k = 0; k < resb.size(); k++ )
        cout << resb[k] << endl;

    return 0;
}