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<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
typedef long double ld;
const ld INF = (ld)10000000000000;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
map<int, int> mp;
vector<int> u;
int main() {
	int n, m; cin >> n >> m;
	vector<int> a, b;
	rep(i, n) {
		int z; cin >> z; a.push_back(z);
		mp[z]++; u.push_back(z);
	}
	rep(i, m) {
		int z; cin >> z; b.push_back(z);
		mp[z]++; u.push_back(z);
	}
	//and
	vector<int> an;
	rep(i, n) {
		if (mp[a[i]] >= 2)an.push_back(a[i]);
	}
	rep(i, m) {
		if (mp[b[i]] >= 2)an.push_back(b[i]);
	}
	sort(an.begin(), an.end());
	int len = unique(an.begin(), an.end()) - an.begin();
	cout << len << " ";
	sort(u.begin(), u.end());
	int len2 = unique(u.begin(), u.end()) - u.begin();
	cout << len2 << endl;
	rep(i, len) {
		cout << an[i] << endl;
	}
	rep(i, len2) {
		cout << u[i] << endl;
	}
	//stop
	return 0;
}

C++: #include<bits/stdc++.h>

using namespace std;

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

  vector<int> a;
  vector<int> b;
  int tmp;
  for(int i = 0;i < n+m;++i){
    cin>>tmp;
    if(i < n){
      a.push_back(tmp);
    }
    else{
      b.push_back(tmp);
    }
  }

  vector<int> an;
  set_intersection(a.begin(),a.end(),b.begin(),b.end(),back_inserter(an));
  sort(an.begin(),an.end());

  b.insert(b.end(),a.begin(),a.end());
  sort(b.begin(),b.end());
  b.erase(unique(b.begin(),b.end()),b.end());

  cout<<an.size()<<" "<<b.size()<<endl;
  for(int e : an){
    cout<<e<<endl;
  }
  for(int e : b){
    cout<<e<<endl;
  }

return 0;
}

C++: #define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, m, n) for(int i=(m); i<(n); ++i)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define Cout(x) cout << (x) << endl
#define Cout2(x, y) cout << (x) << " " << (y) << endl
#define dump(x) cerr << #x << " = " << (x) << endl;
typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<vector<int>> VVI;
typedef pair<int, int> PII;
const int inf = 1e9;
const double pi = acos(-1.0);

int main() {
	int n, m; cin >> n >> m;
	VI a(n), b(m);
	rep(i, n)cin >> a[i];
	rep(i, m)cin >> b[i];

	VI ans1, ans2;
	set_intersection(all(a), all(b), inserter(ans1, ans1.end()));
	set_union(all(a), all(b), inserter(ans2, ans2.end()));
	Cout2(sz(ans1), sz(ans2));
	for (auto x : ans1)cout << x << endl;
	for (auto x : ans2)cout << x << endl;
}

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(a[ap]<b[bp]){
            i = a[ap];
        }else{
            i = b[bp];
        }
    }
    
    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 <math.h>
#include <stdlib.h>
#include <string.h>
#include <algorithm>
#include <array>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define loop(i, a, n) for (int i = a; i < (n); i++)
#define all(in) in.begin(), in.end()
#define INF = 1e9;
#define MOD = 1e9 + 7;

int main() {
    int n, m;
    cin >> n >> m;
    vector<int> a(n), b(m);
    rep(i, n) cin >> a[i];
    rep(i, m) cin >> b[i];
    set<int> inter, uni;
    set<int> set_b;
    rep(i, m) set_b.insert(b[i]);
    rep(i, n) {
        if (set_b.count(a[i]) == 1) inter.insert(a[i]);
    }
    rep(i, n) uni.insert(a[i]);
    rep(i, m) uni.insert(b[i]);
    cout << inter.size() << " " << uni.size() << endl;
    for (int x : inter) cout << x << endl;
    for (int x : uni) cout << x << endl;
    return 0;
}