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++: #define _CRT_SECURE_NO_WARNINGS
#define _SILENCE_ALL_CXX17_DEPRECATION_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include <map>
#include <fstream>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <assert.h>
#include <complex>
using namespace std;
#define LONG_INF 10000000000000
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007
#define MOD 998244353LL
#define seg_size 65536*4
#define REP(i,n) for(long long i = 0;i < n;++i)
int main() {
	int n, m;
	cin >> n >> m;
	map<int, int> a;
	vector<int> b, c;
	REP(i, n+m) {
		int d;
		cin >> d;
		a[d]++;
	}
	for (auto i = a.begin(); i != a.end(); ++i) {
		c.push_back(i->first);
		if (i->second == 1) {

		}
		else b.push_back(i->first);
	}
	sort(b.begin(), b.end());
	sort(c.begin(), c.end());
	cout << b.size() << " " << c.size() << endl;
	REP(i, b.size()) {
		cout << b[i] << endl;
	}
	REP(i, c.size()) {
		cout << c[i] << endl;
	}
	return 0;
}

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

int main(){
    int N, M;
    cin >> N >> M;
    map<int, int> mp;
    for(int i=0; i<N+M; i++){
        int a;
        cin >> a;
        mp[a]++;
    }
    vector<int> And, Or;
    for(auto& p : mp){
        if(p.second == 2) And.push_back(p.first);
        Or.push_back(p.first);
    }
    cout << And.size() << " " << Or.size() << endl;
    for(int a : And) cout << a << endl;
    for(int a : Or) cout << a << endl;
}

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

typedef long long ll;
typedef unsigned long long ull;

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

  vector<ll> a(n);
  vector<ll> b(m);

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

  map<ll, ll> c;
  for (ll i = 0; i < n; ++i) {
    c[a[i]] = 1;
  }
  for (ll i = 0; i < m; ++i) {
    auto itr = c.find(b[i]);
    if (itr == c.end()) c[b[i]] = 1;
    else itr->second++;
  }

  vector<ll> ansa;
  vector<ll> ansb;
  for (auto itr = c.begin(); itr != c.end(); ++itr) {
    ansb.push_back(itr->first);
    if (itr->second == 2) {
      ansa.push_back(itr->first);
    }
  }
  sort(ansa.begin(), ansa.end());
  sort(ansb.begin(), ansb.end());

  cout << ansa.size() << " " << ansb.size() << endl;
  for (ll i = 0; i < ansa.size(); ++i) {
    cout << ansa[i] << endl;
  }
  for (ll i = 0; i < ansb.size(); ++i) {
    cout << ansb[i] << endl;
  }

  return 0;
}

C++: /*  -*- coding: utf-8 -*-
 *
 * 2930.cc: 
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 200000;

/* typedef */

/* global variables */

int as[MAX_N], bs[MAX_N];
int ds[MAX_N], os[MAX_N * 2];

/* subroutines */

/* main */

int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; i++) scanf("%d", as + i);
  for (int i = 0; i < m; i++) scanf("%d", bs + i);

  int dn = 0, on = 0;
  int ai = 0, bi = 0;
  while (ai < n && bi < m) {
    if (as[ai] < bs[bi])
      os[on++] = as[ai++];
    else if (as[ai] > bs[bi])
      os[on++] = bs[bi++];
    else
      ds[dn++] = os[on++] = as[ai++], bi++;
  }
  while (ai < n) os[on++] = as[ai++];
  while (bi < m) os[on++] = bs[bi++];

  printf("%d %d\n", dn, on);
  for (int i = 0; i < dn; i++) printf("%d\n", ds[i]);
  for (int i = 0; i < on; i++) printf("%d\n", os[i]);
  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;
    while(ap!=n or bp!=m){
        i++;
        
        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++;
    }
    
    cout << dup.size() <<" "<< all.size()  << endl;
    
    for(int i=0;i<dup.size();i++){
        cout << dup[i] << endl;
    }
    for(int i=0;i<all.size();i++){
        cout << all[i] << endl;
    }
    return 0;
}

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

int main() {
	int n, m;
	cin >> n >> m;
	vector<int> a(n), b(m), c, d;
	for (int& i : a) cin >> i;
	for (int& i : b) cin >> i;
	set_intersection(a.begin(), a.end(), b.begin(), b.end(), inserter(c, c.end()));
	set_union(a.begin(), a.end(), b.begin(), b.end(), inserter(d, d.end()));
	cout << c.size() << ' ' << d.size() << endl;
	for (int& i : c) cout << i << endl;
	for (int& i : d) cout << i << endl;
}