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<map>
#include<vector>
using namespace std;
int main(){
    int n,m;
    cin >> n >> m;
    map<int,int> ma;
    for(int i = 0; i < n; i++){
        int a;
        cin >> a;
        ma[a]++;
    }
    for(int i = 0; i < m; i++){
        int a;
        cin >> a;
        ma[a]++;
    }
    vector<int> ans1,ans2;//and,or
    for(auto itr = ma.begin(); itr != ma.end(); itr++){
        int id = itr->first;
        int cnt = itr->second;
        if(cnt == 2)ans1.push_back(id);
        ans2.push_back(id);
    }
    cout << ans1.size() << " " << ans2.size() << endl;
    for(int i = 0; i < ans1.size(); i++){
        cout << ans1[i] << endl;
    }
    for(int i = 0; i < ans2.size(); i++){
        cout << ans2[i] << endl;
    }
}

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

int main()
{
	ios::sync_with_stdio(false), cin.tie(0);
	int n, m;
	cin >> n >> m;
	vector<int> a(n), b(m);
	set<int> dic;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		dic.insert(a[i]);
	}
	vector<int> an, o = a;
	for (int i = 0; i < m; i++) {
		cin >> b[i];
		if (dic.count(b[i])) an.push_back(b[i]);
		o.push_back(b[i]);
	}
	sort(an.begin(), an.end());
	sort(o.begin(), o.end());
	o.erase(unique(o.begin(), o.end()), o.end());
	printf("%d %d\n", (int)an.size(), (int)o.size());
	for (auto val : an) {
		printf("%d\n", val);
	}
	for (auto val : o) {
		printf("%d\n", val);
	}
	return 0;
}

C++: #include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧  
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     
　　　　／　　　＼　 　 |　|     
　　　 /　　 /￣￣￣￣/　　|  
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿  
　 　　　＼/＿＿＿＿/　（u　⊃  
---------------------------------------------------------------------------------------------------*/












int N, M, A[201010], B[201010];
//---------------------------------------------------------------------------------------------------
void _main() {
    cin >> N >> M;
    rep(i, 0, N) cin >> A[i];
    rep(i, 0, M) cin >> B[i];

    vector<int> ansand, ansor;
    int a = 0, b = 0;
    while (a < N and b < M) {
        if (A[a] == B[b]) {
            ansand.push_back(A[a]);
            ansor.push_back(A[a]);
            a++; b++;
        } else if (A[a] < B[b]) {
            ansor.push_back(A[a]);
            a++;
        } else {
            ansor.push_back(B[b]);
            b++;
        }
    }
    while (a < N) {
        ansor.push_back(A[a]);
        a++;
    }
    while (b < M) {
        ansor.push_back(B[b]);
        b++;
    }

    int A = ansand.size();
    int B = ansor.size();

    printf("%d %d\n", A, B);
    fore(i, ansand) printf("%d\n", i);
    fore(i, ansor) printf("%d\n", i);
}

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

int main(){
    int n, m;
    map<int,int> ma;
    cin >> n >> m;
    for(int i = 0; i < n+m; i++){
        int a;  cin >> a;
        ma[a]++;
    }
    vector<int> a, b;
    for(auto p : ma){
        if(p.second == 2)  a.push_back(p.first);
        b.push_back(p.first);
    }
    cout << a.size() << " " << b.size() << endl;
    for(int x : a)  cout << x << endl;
    for(int x : b)  cout << x << endl;
    return 0;
}

C++: #define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  int n, m;
  cin >> n >> m;
  set<int> st1, st2;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    st1.insert(x);
    st2.insert(x);
  }
  vector<int> a;
  for (int i = 0; i < m; i++) {
    int x;
    cin >> x;
    st1.insert(x);
    if (st2.count(x)) a.push_back(x);
  }
  sort(a.begin(), a.end());
  cout << (int) a.size() << " " << st1.size() << endl;
  for (int i = 0; i < (int) a.size(); i++) {
    cout << a[i] << endl;
  }
  for (int i : st1) {
    cout << i << endl;
  }
  return 0;	
}

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

int main() {
    int n, m;
    cin >> n >> m;
    set<int> a, b;
    for (int i = 0; i < n; ++i) {
        int x;
        cin >> x;
        a.insert(x);
    }
    for (int i = 0; i < m; ++i) {
        int x;
        cin >> x;
        b.insert(x);
    }
    int A = 0, B = 0;
    set<int> And, Or;
    for (auto p : a) {
        if (b.count(p)) {
            And.insert(p);
            ++A;
        }
        Or.insert(p);
    }
    for (auto p : b) {
        Or.insert(p);
    }

    cout << And.size() << " " << Or.size() << endl;
    for (auto p : And) {
        cout << p << endl;
    }
    for (auto p : Or) {
        cout << p << endl;
    }
    return 0;
}