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;

int main() {
    int n, m;
    cin >> n >> m;
    set<int> OR;
    set<int> AND;
    set<int> a;
    set<int> b;
    for(int i = 1; i <= n; i++) {
        int in;
        cin >> in;
        a.insert(in);
        OR.insert(in);
    }
    for(int i = 1; i <= m; i++) {
        int in;
        cin >> in;
        OR.insert(in);
        if(a.find(in) != a.end()) AND.insert(in);
    }
    cout << AND.size() << " " << OR.size() << endl;
    for(auto itr = AND.begin(); itr != AND.end(); itr++) {
        cout << *itr << endl;
    }
    for(auto itr = OR.begin(); itr != OR.end(); itr++) {
        cout << *itr << 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++: #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;
}