Go: package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	return &Scanner{sc}
}

func (sc *Scanner) NextInt() int {
	sc.sc.Scan()
	i, err := strconv.Atoi(sc.sc.Text())
	if err != nil {
		panic(err)
	}
	return i
}

func main() {
	sc := NewScanner()

	n := sc.NextInt()
	m := sc.NextInt()

	mp := map[int]int{}
	for i := 0; i < n; i++ {
		mp[sc.NextInt()]++
	}
	for i := 0; i < m; i++ {
		mp[sc.NextInt()]++
	}
	var and, or []int
	for k, v := range mp {
		if v >= 1 {
			or = append(or, k)
		}
		if v == 2 {
			and = append(and, k)
		}
	}
	sort.Ints(and)
	sort.Ints(or)
	fmt.Println(len(and), len(or))
	for _, v := range and {
		fmt.Println(v)
	}
	for _, v := range or {
		fmt.Println(v)
	}
}

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

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