Go: package main

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

func main() {
	var n, m int
	fmt.Scan(&n, &m)

	mm := make(map[int]bool)
	am := make(map[int]bool)
	om := make(map[int]bool)

	var sc = bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	for i := 0; i < n; i++ {
		sc.Scan()
		a, _ := strconv.Atoi(sc.Text())
		mm[a] = true
		om[a] = true
	}
	for i := 0; i < m; i++ {
		sc.Scan()
		b, _ := strconv.Atoi(sc.Text())
		if bl, ok := mm[b]; ok && bl {
			am[b] = true
		}
		om[b] = true
	}
	fmt.Printf("%d %d\n", len(am), len(om))
	as := make([]int, 0)
	for k := range am {
		as = append(as, k)
	}
	sort.Sort(sort.IntSlice(as))
	os := make([]int, 0)
	for k := range om {
		os = append(os, k)
	}
	sort.Sort(sort.IntSlice(os))
	for i := range as {
		fmt.Println(as[i])
	}
	for i := range os {
		fmt.Println(os[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;
}

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