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>
  
using namespace std;
  
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--)
#define pb push_back
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second
  
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
const int INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;

int main(){
    int n, m;
    cin >> n >> m;
    set<int> a, b;
    rep(i, n) {
        int x;
        cin >> x;
        a.insert(x);
    }
    rep(i, m) {
        int x;
        cin >> x;
        b.insert(x);
    }
    set<int> x, y;
    for(auto&& i : a) x.insert(i);
    for(auto&& i : b) x.insert(i);
    for(auto&& i : a) if(b.count(i)) y.insert(i);
    cout << y.size() << " " << x.size() << endl;
    for(auto&& i : y) cout << i << endl;
    for(auto&& i : x) cout << i << endl;
    return 0;
}

C++: #include <iostream>
using namespace std;
int main(void){
    int n, m, i, j, n_and, n_xor;
    cin >> n >> m;
    int a[n], b[m], logand[n > m ? n : m], logxor[n + m];
    for(int k = 0; k < n; k++) cin >> a[k];
    for(int k = 0; k < m; k++) cin >> b[k];

    i = j = n_and = n_xor = 0;
    while(i < n && j < m){
        if(a[i] == b[j]){
            logand[n_and++] = a[i++];
            j++;
        } else if(a[i] > b[j]){
            logxor[n_xor++] = b[j++];
        } else {
            logxor[n_xor++] = a[i++];
        }
    }
    for(int k = i; k < n; k++) logxor[n_xor++] = a[k];
    for(int k = j; k < m; k++) logxor[n_xor++] = b[k];

    cout << n_and << " " << n_and + n_xor << endl;
    for(int k = 0; k < n_and; k++) cout << logand[k] << endl;
    i = j = 0;
    while(i < n_and && j < n_xor){
        if(logand[i] < logxor[j]) cout << logand[i++] << endl;
        else cout << logxor[j++] << endl;
    }
    for(int k = i; k < n_and; k++) cout << logand[k] << endl;
    for(int k = j; k < n_xor; k++) cout << logxor[k] << endl;

    return 0;   
}

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++;
        if(a[ap]==i or b[bp]==i) b_s++;

        while(a[ap]<=i and ap!=n) ap++;
        while(b[bp]<=i and bp!=m) bp++;
    }
    
    cout << a_s <<" "<< b_s << endl;
    
    while(ap!=n or bp!=m){
        i++;
        
        if(a[ap]==i and b[bp]==i) cout<<i<<endl;

        while(a[ap]<=i and ap!=n) ap++;
        while(b[bp]<=i and bp!=m) bp++;
    }
    
    while(ap!=n or bp!=m){
        i++;
        
        if(a[ap]==i or b[bp]==i) cout<<i<<endl;

        while(a[ap]<=i and ap!=n) ap++;
        while(b[bp]<=i and bp!=m) bp++;
    }
    
    return 0;
}

C++: #include <iostream>
#include <set>
#include <vector>
#include <string>
#include <algorithm>
#include <iterator>
#include <map>
#include <utility>
#include <list>
#include <climits>
#include <bitset>
#include <numeric>

using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)
#define repi(i, n) for(auto i = (n).begin(); i != (n).end(); i++)
#define in_arr(type, a, n) copy_n(istream_iterator<type>(cin), n, (a).begin());
#define ll long long int

int main(){
    int n, m;
    cin >> n >> m;
    set<int> a, o, s, t;
    
    rep(i, n){
        int l;
        cin >> l;
        t.insert(l);
        o.insert(l);
    }
    
    rep(i, m){
        int l;
        cin >> l;
        s.insert(l);
        o.insert(l);
    }
    
    repi(i, s){
        if(t.find(*i) != t.end()){
            a.insert(*i);
        }
    }
    cout << a.size() << " " << o.size() << endl;
    repi(i, a){
        cout << *i << endl;
    }
    repi(i, o){
        cout << *i << endl;
    }
    
    return 0;
}

C++: #include <bits/stdc++.h>
#define int long long
#define endl '\n'
#define FOR(i, a, n) for (int i = (a); i < (n); ++i)
#define REP(i, n) FOR(i, 0, n)
using namespace std;

void _main() {
    int n, m;
    cin >> n >> m;
    map<int, int> mp;
    REP (i, n) {
        int a;
        cin >> a;
        mp[a]++;
    }
    REP (i, m) {
        int b;
        cin >> b;
        mp[b]++;
    }
    vector<int> v, u;
    for (auto p : mp) {
        if (p.second == 2) v.push_back(p.first);
        u.push_back(p.first);
    }
    cout << v.size() << " " << u.size() << endl;
    for (int vv : v) cout << vv << endl;
    for (int uu : u) cout << uu << endl;
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(10);
    _main();
    return 0;
}