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;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

//#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = 1'000'000'007;
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; }

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N, M; cin >> N >> M;
	map<int, int> mp;
	vector<int> a(N); rep(i, 0, N) {
		cin >> a[i];
	}
	vector<int> b(M); rep(i, 0, M) {
		cin >> b[i];
	}

	rep(i, 0, N)mp[a[i]]++;
	rep(i, 0, M)mp[b[i]]++;

	vector<int> v1;
	vector<int> v2;

	for (auto v : mp) {
		if (v.second == 2)v1.emplace_back(v.first);
		if (v.second >= 1)v2.emplace_back(v.first);
	}

	cout << v1.size() << " " << v2.size() << endl;
	rep(i, 0, v1.size()) { cout << v1[i] << endl; }
	rep(i, 0, v2.size()) { cout << v2[i] << 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++;
            dup.push_back(i);  
        } 
        if(a[ap]==i or b[bp]==i){
            b_s++;
            all.push_back(i);
        }
        

        while(a[ap]<=i and ap!=n) ap++;
        while(b[bp]<=i and bp!=m) bp++;
    }
    
    cout << a_s <<" "<< b_s << 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++: //↓template↓

#include "bits/stdc++.h"
using namespace std;
#define Would
#define you
#define all(n)  n.begin(),n.end()
const long long INF = 1e18;
const long long MOD = 1e9 + 7;
const double pi = acos(-1);
const int SIZE = 1 << 17;
int dx[] = { 1,0 }, dy[] = { 0,1 }, alp[30];
long long fac[200005], finv[200005], inv[200005];
vector<long long>dij;
struct edge { long long to, cost; };
vector<vector<edge> >G;

long long mod_pow(long long a, long long b) {
	long long res = 1, mul = a;
	for (int i = 0; i < 31; ++i) {
		if (b >> i & 1) {
			res *= mul;
			res %= MOD;
		}
		mul = (mul * mul) % MOD;
	}

	return res;
}

void addedge(int from, int to, int cost) {
	G[from].push_back({ to,cost });
	G[to].push_back({ from,cost });
}

//↑template↑


long long a, b, k[200005], l[200005], mon;
queue<long long>ans;
set<long long>s;
int main() {
	cin >> a >> b;
	for (int i = 0; i < a; ++i) {
		cin >> k[i];
		s.insert(k[i]);
	}

	for (int i = 0; i < b; ++i) {
		cin >> l[i];
		s.insert(l[i]);
	}

	for (int i = 0; i < a; ++i) {
		while (mon < b&&l[mon] < k[i]) { ++mon; }
		if (mon == b) { break; }
		if (l[mon] == k[i]) {
			ans.push(k[i]);
			++mon;
		}
	}

	cout << ans.size() << " " << s.size() << endl;

	while (!ans.empty()) {
		cout << ans.front() << endl;
		ans.pop();
	}
	while (!s.empty()) {
		auto itr = s.begin();
		cout << *itr << endl;
		s.erase(s.begin());
	}
}

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

#define int long long

signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  int N;
  int H, W;  
  string s;

  cin >> N;

  int M;
  cin >> M;
  
  vector<int> A(N, 0);
  vector<int> B(N, 0);  
  int ans = 0;

  map<int, int> c;
  for ( int i = 0; i < N; i++ ) {
    int a;
    cin >> a;
    c[a]++;
  }
  for ( int i = 0; i < M; i++ ) {
    int a;
    cin >> a;
    c[a]++;
  }

  int ans1 = 0, ans2 = 0;  
  for ( pair<int, int> a : c ) {
    if ( a.second == 2 ) ans1++;    
  }

  for ( pair<int, int> a : c ) {
    if ( a.second >= 1 ) ans2++;    
  }

  cout << ans1 << " " << ans2 << endl;
  for ( pair<int, int> a : c ) {
    if ( a.second == 2 ) cout << a.first << endl; 
  }

  for ( pair<int, int> a : c ) {
    if ( a.second >= 1 ) cout << a.first << endl;
  }
  
  return 0;
}

C++: #include <iostream>
#include <set>
#define int long long
using namespace std;
int n, m, p;
set<int>s, t;
signed main() {
	cin >> n >> m;
	for (int i = 0; i < n; i++) {
		cin >> p;
		s.insert(p);
	}
	for (int j = 0; j < m; j++) {
		cin >> p;
		if (*(s.lower_bound(p)) == p)t.insert(p);
		else s.insert(p);
	}
	cout << t.size() << ' ' << s.size() << endl;
	for (auto i : t)cout << i << endl;
	for (auto i : s)cout << i << endl;
}

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;
}