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++: /*  -*- coding: utf-8 -*-
 *
 * 2930.cc: 
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 200000;

/* typedef */

/* global variables */

int as[MAX_N], bs[MAX_N];
int ds[MAX_N], os[MAX_N * 2];

/* subroutines */

/* main */

int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; i++) scanf("%d", as + i);
  for (int i = 0; i < m; i++) scanf("%d", bs + i);

  int dn = 0, on = 0;
  int ai = 0, bi = 0;
  while (ai < n && bi < m) {
    if (as[ai] < bs[bi])
      os[on++] = as[ai++];
    else if (as[ai] > bs[bi])
      os[on++] = bs[bi++];
    else
      ds[dn++] = os[on++] = as[ai++], bi++;
  }
  while (ai < n) os[on++] = as[ai++];
  while (bi < m) os[on++] = bs[bi++];

  printf("%d %d\n", dn, on);
  for (int i = 0; i < dn; i++) printf("%d\n", ds[i]);
  for (int i = 0; i < on; i++) printf("%d\n", os[i]);
  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(int i=0;i<dup.size();i++){
        cout << dup[i] << endl;
    }
    for(int i=0;i<all.size();i++){
        cout << all[i] << endl;
    }
    return 0;
}

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

int main() {
	int n, m;
	cin >> n >> m;
	vector<int> a(n), b(m), c, d;
	for (int& i : a) cin >> i;
	for (int& i : b) cin >> i;
	set_intersection(a.begin(), a.end(), b.begin(), b.end(), inserter(c, c.end()));
	set_union(a.begin(), a.end(), b.begin(), b.end(), inserter(d, d.end()));
	cout << c.size() << ' ' << d.size() << endl;
	for (int& i : c) cout << i << endl;
	for (int& i : d) cout << i << endl;
}

C++: #include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
typedef long long int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define MOD (1000000007)
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1}; // 移動方向

ll n,m;
vector<ll> a,b;

void input(){
    cin >> n >> m;
    a.resize(n);
    b.resize(m);
    for(int i=0;i<n;i++) cin >> a[i];
    for(int i=0;i<m;i++) cin >> b[i];
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    input();
    vector<ll> andv,orv;
    set_intersection(a.begin(), a.end(), b.begin(), b.end(), back_inserter(andv));
    set_union(a.begin(), a.end(), b.begin(), b.end(), back_inserter(orv));
    cout << andv.size() << ' ' << orv.size() << endl;
    for(auto e:andv) cout << e << endl;
    for(auto e:orv) cout << e << endl;
}