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 <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++: #include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main(){
	int n,m;
	cin >> n >> m;
	vector<int> a(n),b(m);
	for(int i=0; i<n; i++){
		cin >> a[i];
	}
	for(int i=0; i<m; i++){
		cin >> b[i];
	}
	vector<int> res_and, res_or;
	set_intersection(a.begin(), a.end(), b.begin(), b.end(), back_inserter(res_and));
	set_union(a.begin(), a.end(), b.begin(), b.end(), back_inserter(res_or));
	cout << res_and.size() << " " << res_or.size() << endl;
	for(int i: res_and){
		cout << i << endl;
	}
	for(int i: res_or){
		cout << i << endl;
	}
	return 0;
}

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

int main() {
    int n, m;
    while (cin >> n >> m) {
        map<int,int> a;
        for (int i = 0; i < n; ++i) {
            int c; cin >> c;
            a[c]++;
        }
        for (int i = 0; i < m; ++i) {
            int c; cin >> c;
            a[c]++;
        }
        vector<int> And, Or;
        for (auto it : a) {
            if (it.second == 2) And.push_back(it.first);
            Or.push_back(it.first);
        }
        cout << And.size() << " " << Or.size() << endl;
        for (auto v : And) cout << v << endl;
        for (auto v : Or) cout << v << endl;
    }
}

C++: #include<bits/stdc++.h>

using namespace std;

int main(){

  int n,m;

  cin>>n;
  cin>>m;

  vector<int> a(n);
  vector<int> b(m);

  for(int i=0;i<n;++i)
	cin>>a[i];

  for(int i=0;i<m;++i)
	cin>>b[i];

  int cnt_a = 0;
  int cnt_b = 0;

  vector<int> ans;
  vector<int> and_ans;
  vector<int> or_ans;

  for(auto i:a)
	ans.push_back(i);

  for(auto i:b)
	ans.push_back(i);

  sort(ans.begin(),ans.end());  
  
  for(int i=0;i<ans.size()-1;++i){
	if(ans[i] == ans[i+1]){
	  and_ans.push_back(ans[i]);
	  or_ans.push_back(ans[i]);
	  i++;
	}
	else
	  or_ans.push_back(ans[i]);
  }

  if(ans[ans.size()-1] != ans[ans.size()-2])
	or_ans.push_back(ans[ans.size()-1]);
	
  cout<<and_ans.size()<<" "<<or_ans.size()<<endl;

  for(auto i:and_ans)
	cout<<i<<endl;

  for(auto i:or_ans)
	cout<<i<<endl;
  
}

C++: #include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <bitset>
#include <map>
#include <tuple>
#include <unordered_set>
#include <unordered_map>
#include <list>
#include <numeric>
#include <utility>
#include <iterator>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <ctime>
#include <cassert>
#include <random>
#include <cstring>


#define rep(i,n) for(int i=0;i<int(n);i++)
#define all(x) (x).begin(),x.end()
#define pb push_back

using namespace std;
using ll = long long;

const ll mod = 1000000007;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int ddx[8]={-1,-1,0,1,1,1,0,-1};
int ddy[8]={0,1,1,1,0,-1,-1,-1};
bool debug=false;

/*---------------------------------------------------*/

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

  int and_cnt = 0, or_cnt = 0;
  for(auto itr : mp){
    or_cnt++;
    if(mp[itr.first] == 2) and_cnt++;
  }
  cout << and_cnt << " " << or_cnt << endl;

  for(auto itr : mp){
    if(itr.second == 2) cout << itr.first << endl;
  }
  for(auto itr : mp){
    cout << itr.first << endl;
  }
  return 0;
}

C++: #define _CRT_SECURE_NO_WARNINGS
#define _SILENCE_ALL_CXX17_DEPRECATION_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include <map>
#include <fstream>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <assert.h>
#include <complex>
using namespace std;
#define LONG_INF 10000000000000
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007
#define MOD 998244353LL
#define seg_size 65536*4
#define REP(i,n) for(long long i = 0;i < n;++i)
int main() {
	int n, m;
	cin >> n >> m;
	map<int, int> a;
	vector<int> b, c;
	REP(i, n+m) {
		int d;
		cin >> d;
		a[d]++;
	}
	for (auto i = a.begin(); i != a.end(); ++i) {
		c.push_back(i->first);
		if (i->second == 1) {

		}
		else b.push_back(i->first);
	}
	sort(b.begin(), b.end());
	sort(c.begin(), c.end());
	cout << b.size() << " " << c.size() << endl;
	REP(i, b.size()) {
		cout << b[i] << endl;
	}
	REP(i, c.size()) {
		cout << c[i] << endl;
	}
	return 0;
}

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

int main(){
    int N, M;
    cin >> N >> M;
    map<int, int> mp;
    for(int i=0; i<N+M; i++){
        int a;
        cin >> a;
        mp[a]++;
    }
    vector<int> And, Or;
    for(auto& p : mp){
        if(p.second == 2) And.push_back(p.first);
        Or.push_back(p.first);
    }
    cout << And.size() << " " << Or.size() << endl;
    for(int a : And) cout << a << endl;
    for(int a : Or) cout << a << endl;
}

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

typedef long long ll;
typedef unsigned long long ull;

int main() {
  ll n, m;
  cin >> n >> m;

  vector<ll> a(n);
  vector<ll> b(m);

  for (ll i = 0; i < n; ++i) {
    cin >> a[i];
  }
  for (ll i = 0; i < m; ++i) {
    cin >> b[i];
  }

  map<ll, ll> c;
  for (ll i = 0; i < n; ++i) {
    c[a[i]] = 1;
  }
  for (ll i = 0; i < m; ++i) {
    auto itr = c.find(b[i]);
    if (itr == c.end()) c[b[i]] = 1;
    else itr->second++;
  }

  vector<ll> ansa;
  vector<ll> ansb;
  for (auto itr = c.begin(); itr != c.end(); ++itr) {
    ansb.push_back(itr->first);
    if (itr->second == 2) {
      ansa.push_back(itr->first);
    }
  }
  sort(ansa.begin(), ansa.end());
  sort(ansb.begin(), ansb.end());

  cout << ansa.size() << " " << ansb.size() << endl;
  for (ll i = 0; i < ansa.size(); ++i) {
    cout << ansa[i] << endl;
  }
  for (ll i = 0; i < ansb.size(); ++i) {
    cout << ansb[i] << endl;
  }

  return 0;
}