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 rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i < (n); i++)
#define all(v) (v).begin(), (v).end()
using namespace std;
typedef long long LL;
const int INF = 999999999;

int main(){
    int n,m;
    cin >> n >> m;
    vector<int> a(n), b(m);
    set<int> an, o;
    rep(i, n) cin >> a[i];
    rep(i, m) cin >> b[i];
    rep(i, n) o.insert(a[i]);
    rep(i, m){
        if(o.find(b[i]) != o.end()){
            an.insert(b[i]);
        }
    }
    rep(i, m) o.insert(b[i]);
    cout << an.size() << " " << o.size() << endl;
    for(auto &x: an) cout << x << endl;
    for(auto &x: o) cout << x << endl;

}

C++: #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define INF 100000000
#define rep(i,s,n) for (int i = (int)(s); i < (int)(n); i++)
ll mod = 1000000007;

int main(){
    int n,m;cin>>n>>m;
    int i=0,j=0;
    vector<int> a(n);
    vector<int> b(m);
    rep(k,0,n) cin>>a[k];
    rep(k,0,m) cin>>b[k];
    vector<int> an;
    vector<int> or1;
    while(i<n){
        bool flag = true;
        while(j<m&&b[j]<=a[i]){
            if (b[j]==a[i]) {
                an.push_back(a[i]);
                flag = false;
                break;
            }
            or1.push_back(b[j]);
            j++;
        }
        if (flag){
            or1.push_back(a[i]);
        }
        i++;
    }
    while (j<m){
        or1.push_back(b[j]);
        j++;
    }
    cout<<an.size()<<" "<<or1.size()<<endl;
    for(int k:an){
        cout<<k<<endl;
    }
    for(int k:or1){
        cout<<k<<endl;
    }
}

C++: // includes {{{
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<tuple>
#include<cmath>
#include<random>
#include<cassert>
// #include<deque>
// #include<multiset>
// #include<bitset>
// #include<cstring>
// #include<bits/stdc++.h>
// }}}
using namespace std;
using ll = long long;

int main() {
  ios::sync_with_stdio(false), cin.tie(0);
  int n, m;
  cin >> n >> m;
  set<int> st;
  for(int i = 0; i < n; i++) {
    int x;
    cin >> x;
    st.insert(x);
  }
  auto OR = st;
  set<int> AND;
  for(int i = 0; i < m; i++) {
    int x;
    cin >> x;
    OR.insert(x);
    if(st.count(x)) AND.insert(x);
  }
  cout << AND.size() << " " << OR.size() << "\n";
  for(auto a : AND) cout << a << "\n";
  for(auto a : OR) cout << a << "\n";
  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(auto itr = dup.begin(); itr != dup.end(); ++itr) {
        cout << *itr << endl;
    }
    for(auto itr = all.begin(); itr != all.end(); ++itr) {
        cout << *itr << endl;
    }

    return 0;
}

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n, m;
    cin >> n >> m;
    vector<int> as(n), bs(m), isec;
    set<int> ss;
    for (int i = 0; i < n; i++) {
        cin >> as[i];
        ss.insert(as[i]);
    }
    for (int i = 0; i < m; i++) {
        cin >> bs[i];
        ss.insert(bs[i]);
    }
    sort(as.begin(), as.end());
    sort(bs.begin(), bs.end());
    set_intersection(as.begin(), as.end(), bs.begin(), bs.end(), back_inserter(isec));
    cout << isec.size() << ' ' << ss.size() << endl;
    for (int c : isec) {
        cout << c << '\n';
    }
    for (int s : ss) {
        cout << s << '\n';
    }
}

C++: #include <bits/stdc++.h>
#define inf 1000000000 //1E+9
using namespace std;

int main(){
	int n, m; cin>>n>>m;
	set<int> a,b,Or;
	int p;
	for(int i=0;i<n;i++){ cin>>p; a.insert(p); Or.insert(p);}
	for(int i=0;i<m;i++){ cin>>p; b.insert(p); Or.insert(p);}
	vector<int> And;
	for(auto i=a.begin(); i!=a.end(); i++){
		if(b.count(*i)) And.push_back(*i);
	}
	cout<<And.size()<<" "<<Or.size()<<endl;
	for(int i=0; i<And.size(); i++) cout<<And[i]<<endl;
	for(auto i=Or.begin(); i!=Or.end(); i++)cout<<*i<<endl;


	return 0;
}