Problem:
A: 情報検索 / Information Search
問題
ポスティングリストとは、検索語と出現文書 ID の対応関係を持たせたリストである。例えば
北海道: 1, 2, 4, 9
観光: 1, 3, 4, 7
などである。
上記のポスティングリストから、and 検索をすると、ID 1, 4 の文書がヒットし、or 検索をすると、ID 1, 2, 3, 4, 7, 9 がヒットする。
ここで and 検索とは「どちらのリストにも含まれる要素を列挙する」ことであり、 or 検索とは「少なくともどちらか一方のリストに含まれる要素を列挙する」ことである。
ポスティングリストが与えられるので、and 検索と or 検索の結果をそれぞれ出力せよ。
入力形式
n
m
a_1
a_2
$\ldots$
a_n
b_1
b_2
$\ldots$
b_m
入力はすべて整数からなる。
1 行目には検索すべき 2 つのポスティングリストの長さ
n
と
m
が空白区切りで与えられる。
2 行目と 3 行目にはそれぞれのポスティングリストに含まれる ID が空白区切りで与えられる。
制約
1 \leq n, m \leq 2\times10^5
a_i
<
a_j
(
i < j
)
b_i
<
b_j
(
i < j
)
1 \leq a_i, b_i \leq 10^9
出力形式
and 検索のヒット数を
A
、or 検索のヒット数を
B
とする。
最初の一行に
A
B
の順に空白区切りで出力せよ。
続く
A
行に and 検索でヒットした ID を昇順に出力せよ。
続く
B
行に or 検索でヒットした ID を昇順に出力せよ。
入力例1
4 4
1 2 4 9
1 3 4 7
出力例1
2 6
1
4
1
2
3
4
7
9
入力例2
4 4
1 3 5 7
2 4 6 8
出力例2
0 8
1
2
3
4
5
6
7
8
入力例3
3 5
1 2 3
1 2 3 4 5
出力例3
3 5
1
2
3
1
2
3
4
5

Submitted solutions:

code_snippet: #include <bits/stdc++.h>
#define rep(i,j,n) for (int i = j; i < (int)(n); i++)
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define all(x) (x.begin(), x.end())
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b){
  bool compare = (a < b);
  if(compare) a = b;
  return compare;
}
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b){
  bool compare = (a > b);
  if(compare) a = b;
  return compare;
}
string substrback(string s,size_t p,size_t l){
	//s=文字列　p=後ろから数えて何文字目　l=pから何文字目まで
	const size_t strl = s.length();
	return s.substr(strl - p,l);
}
//pair型のfirstで比較
bool comparePairs(const pair<ll,ll> &a, const pair<ll,ll> &b){
	if(a.first != b.first)
	return a.first<b.first;
	return a.second < b.second;
}
//pair型のsecondで比較
bool comparePairs2(const pair<ll,ll> &a, const pair<ll,ll> &b){
	if(a.second != b.second)
	return a.second<b.second;
	return a.first < b.first;
}
//pair型の１.second  と2.firstをつなげていく
bool customsort(const pair<ll,ll>  &a,const pair<ll,ll> &b){
	if(a.second == b.first){
		return true;
	}
	return false;
}
bool customsort2(const pair<ll, ll> &a, const pair<ll, ll> &b) {
    // 特定の値がfirstに出た場合、そのsecond値を先頭に持ってくる
    if (a.first == -1) {
        return true;
    } else if (b.first == -1) {
        return false;
    }
    return a.first < b.first;
}

//nの階乗
ull facto(ll n){
	if (n==0 || n ==1){
		return 1;
	} else {
		return n *facto(n-1);
	}
}
//nのΣ
ll sum(ll n) {
	ll sum =0;
	sum = n*(n+1)/2;
	return sum;
}
//やりましょう!!
int main() {
	int n,m;
	cin>>n>>m;
	vector<int> a(n);
	vector<int> b(m);
	int a1=0;
	int b1;
	set<int> in1;
	set<int> ans;
	set<int> ans2;
	rep(i,0,n){
		cin>>a[i];
		in1.insert(a[i]);
		ans2.insert(a[i]);
	}
	rep(i,0,m){
		cin>>b[i];
		if(in1.count(b[i])){
			ans.insert(b[i]);
			a1++;
		}
		ans2.insert(b[i]);
	}
	a1=ans.size();
	b1=ans2.size();
	cout<<a1<<" "<<b1<<endl;
	for(auto x:ans){
		cout<<x<<endl;
	}
	for(auto x:ans2){
		cout<<x<<endl;
	}
}
accuracy: 1
time_ms: 300
memory_kb: 21032
final_rank: 17

code_snippet: #pragma region Macros
#include <bits/stdc++.h>

using namespace std;

using lint = long long;

using ull = unsigned long long;
using ld = long double;
using int128 = __int128_t;
#define all(x) (x).begin(), (x).end()
#define EPS 1e-8
#define uniqv(v) v.erase(unique(all(v)), v.end())
#define OVERLOAD_REP(_1, _2, _3, name, ...) name
#define REP1(i, n) for (auto i = std::decay_t<decltype(n)>{}; (i) != (n); ++(i))
#define REP2(i, l, r) for (auto i = (l); (i) != (r); ++(i))
#define rep(...) OVERLOAD_REP(__VA_ARGS__, REP2, REP1)(__VA_ARGS__)
#define log(x) cout << x << endl
#define logfixed(x) cout << fixed << setprecision(10) << x << endl;
#define logy(bool)         \
  if (bool) {              \
    cout << "Yes" << endl; \
  } else {                 \
    cout << "No" << endl;  \
  }

ostream &operator<<(ostream &dest, __int128_t value) {
  ostream::sentry s(dest);
  if (s) {
    __uint128_t tmp = value < 0 ? -value : value;
    char buffer[128];
    char *d = end(buffer);
    do {
      --d;
      *d = "0123456789"[tmp % 10];
      tmp /= 10;
    } while (tmp != 0);
    if (value < 0) {
      --d;
      *d = '-';
    }
    int len = end(buffer) - d;
    if (dest.rdbuf()->sputn(d, len) != len) {
      dest.setstate(ios_base::badbit);
    }
  }
  return dest;
}

template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v) {
  for (int i = 0; i < (int)v.size(); i++) {
    os << v[i] << (i + 1 != (int)v.size() ? " " : "");
  }
  return os;
}

template <typename T>
ostream &operator<<(ostream &os, const set<T> &set_var) {
  for (auto itr = set_var.begin(); itr != set_var.end(); itr++) {
    os << *itr;
    ++itr;
    if (itr != set_var.end()) os << " ";
    itr--;
  }
  return os;
}

template <typename T, typename U>
ostream &operator<<(ostream &os, const map<T, U> &map_var) {
  for (auto itr = map_var.begin(); itr != map_var.end(); itr++) {
    os << itr->first << " -> " << itr->second << "\n";
  }
  return os;
}

template <typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U> &pair_var) {
  os << "(" << pair_var.first << ", " << pair_var.second << ")";
  return os;
}

void out() { cout << '\n'; }
template <class T, class... Ts>
void out(const T &a, const Ts &...b) {
  cout << a;
  (cout << ... << (cout << ' ', b));
  cout << '\n';
}

template <typename T>
istream &operator>>(istream &is, vector<T> &v) {
  for (T &in : v) is >> in;
  return is;
}

inline void in(void) { return; }
template <typename First, typename... Rest>
void in(First &first, Rest &...rest) {
  cin >> first;
  in(rest...);
  return;
}

template <typename T>
bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <typename T>
bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

vector<lint> dx8 = {1, 1, 0, -1, -1, -1, 0, 1};
vector<lint> dy8 = {0, 1, 1, 1, 0, -1, -1, -1};
vector<lint> dx4 = {1, 0, -1, 0};
vector<lint> dy4 = {0, 1, 0, -1};

#pragma endregion

int main() {
  cin.tie(0)->sync_with_stdio(0);
  int n, m;
  in(n, m);
  vector<int> xx(n), yy(m), tmp(n + m), cmp1(n), cmp2(m);
  in(xx);
  in(yy);
  tmp = xx;
  rep(i, m) tmp.push_back(yy[i]);
  sort(all(tmp));
  uniqv(tmp);

  rep(i, n) cmp1[i] = distance(tmp.begin(), lower_bound(all(tmp), xx[i]));
  rep(i, m) cmp2[i] = distance(tmp.begin(), lower_bound(all(tmp), yy[i]));
  bitset<300000> a, b, ad, o;
  rep(i, n) {
    a.set(cmp1[i]);
  }

  rep(i, m) {
    b.set(cmp2[i]);
  }
  ad = a & b;
  o = a | b;
  int x = ad.count();
  int y = o.count();
  out(x, y);
  rep(i, 300000) {
    if (ad[i]) {
      out(tmp[i]);
    }
  }
  rep(i, 300000) {
    if (o[i]) {
      out(tmp[i]);
    }
  }
}
accuracy: 1
time_ms: 40
memory_kb: 5972
final_rank: 2

code_snippet: #line 1 "main.cpp"
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
using ll = long long;
#define all(x) x.begin(),x.end()
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }
template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }

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

    vector<int> a(n), b(m);
    map<int, int> mp;

    for (int i = 0; i < n; ++i) {
        cin >> a[i];
        mp[a[i]]++;
    }
    for (int i = 0; i < m; ++i) {
        cin >> b[i];
        mp[b[i]]++;
    }
    int cnta = 0, cntb = 0;
    for (auto &&[x, y] : mp) {
        if (y == 2) cnta++;
        if (y >= 1) cntb++;
    }
    cout << cnta << ' ' << cntb << '\n';
    for (auto &&[x, y] : mp) {
        if (y == 2) {
            cout << x << '\n';
        }
    }
    for (auto &&[x, y] : mp) {
        if (y >= 1) {
            cout << x << '\n';
        }
    }
}
accuracy: 1
time_ms: 100
memory_kb: 14172
final_rank: 5

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

#define rep(i, N) for(ll i = 0; i < (ll)(N); ++i)
#define per(i, N) for(ll i = (ll)(N) - 1; i >= 0; --i)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define bit(n, k) (((n) >> (k)) & 1)
#define pcnt(n) (bitset<64>(n).count())
#define endl '\n'
#define fi first
#define se second
#define mkpr make_pair
#define mktpl make_tuple
#define eb emplace_back
template <class T> std::istream& operator>>(std::istream& is, std::vector<T>& V) {
    for (auto& it : V) is >> it;
    return is;
}
template <class T> std::ostream& operator<<(std::ostream& os, const std::vector<T>& V) {
    for (int i = 0 ; i < (int)V.size() ; i++) {
        os << V[i] << (i + 1 == (int)V.size() ? "" : " ");
    }
    return os;
}
using namespace std;

int main() {
    std::cin.tie(nullptr)->sync_with_stdio(false);
    int n,m;cin>>n>>m;
    map<int,int> A;
    for(int i = 0; n > i; i++){
        int x;cin>>x;A[x]++;
    }
    for(int i = 0; m > i; i++){
        int x;cin>>x;A[x]++;
    }
    vector<int> ans1,ans2;
    for(auto x: A){
        ans1.push_back(x.first);
        if(x.second == 2)ans2.push_back(x.first);
    }
    cout << ans2.size() << " " << ans1.size() << endl;
    sort(ans1.begin(), ans1.end());
    sort(ans2.begin(), ans2.end());
    for(int i = 0; ans2.size() > i; i++)cout << ans2[i] << endl;
    for(int i = 0; ans1.size() > i; i++)cout << ans1[i] << endl;
    
}
accuracy: 1
time_ms: 60
memory_kb: 14196
final_rank: 3

code_snippet: #include <bits/stdc++.h>
using namespace std;
int main() {

    set<int> A,B,C;
    int N,M;
    cin>>N>>M;
    for(int n=0;n<N;n++){
        int a;
        cin>>a;
        A.insert(a);
        C.insert(a);
    }
    for(int m=0;m<M;m++){
        int b;
        cin>>b;
        if(A.count(b))B.insert(b);
        C.insert(b);
    }
    cout<<B.size()<<" "<<C.size()<<endl;
    for(auto b:B)cout<<b<<endl;
    for(auto c:C)cout<<c<<endl;

}
accuracy: 1
time_ms: 290
memory_kb: 20388
final_rank: 16

code_snippet: #include<bits/stdc++.h>
using namespace std;
using ll=long long;
int main(void){
    ll n,m;
    cin>>n>>m;
    vector<ll> a,b,v1,v2;
    for(ll i=0;i<n;i++){
        ll A;
        cin>>A;
        a.push_back(A);
    }
    for(ll i=0;i<m;i++){
        ll B;
        cin>>B;
        b.push_back(B);
    }
    sort(a.begin(),a.end());
    sort(b.begin(),b.end());
    set_intersection(a.begin(),a.end(),b.begin(),b.end(),back_inserter(v1));
    set_union(a.begin(),a.end(),b.begin(),b.end(),back_inserter(v2));
    cout<<v1.size()<<" "<<v2.size()<<"\n";
    for(auto i : v1){
        cout<<i<<endl;
    }
    for(auto i : v2){
        cout<<i<<endl;
    }
    return 0;
}
accuracy: 1
time_ms: 220
memory_kb: 8424
final_rank: 9

code_snippet: #include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
using std::cout;
using std::cin;
using std::endl;
using ll=long long;
using ld=long double;
ll ILL=9167167167167167167;
const int INF=100000000;
const ll mod=998244353;
#define rep(i,a) for (int i=0;i<a;i++)
#define all(p) p.begin(),p.end()
template<class T> using _pq = priority_queue<T, vector<T>, greater<T>>;
template<class T> ll LB(vector<T> &v,T a){return lower_bound(v.begin(),v.end(),a)-v.begin();}
template<class T> ll UB(vector<T> &v,T a){return upper_bound(v.begin(),v.end(),a)-v.begin();}
template<class T> bool chmin(T &a,const T &b){if(a>b){a=b;return 1;}else return 0;}
template<class T> bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}else return 0;}
template<class T> void So(vector<T> &v) {sort(v.begin(),v.end());}
template<class T> void Sore(vector<T> &v) {sort(v.begin(),v.end(),[](T x,T y){return x>y;});}
void yneos(bool a){if(a) cout<<"Yes\n"; else cout<<"No\n";}
template<class T> void vec_out(vector<T> &p){for(int i=0;i<(int)(p.size());i++){if(i) cout<<" ";cout<<p[i];}cout<<"\n";}


void solve();
// oddloop
int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	
	int t=1;
	//cin>>t;
	rep(i,t) solve();
}

void solve(){
	int n,m;
	cin>>n>>m;
	set<int> s,A,B;
	rep(i,n){
		int a;
		cin>>a;
		s.insert(a);
		B.insert(a);
	}
	rep(i,m){
		int a;
		cin>>a;
		B.insert(a);
		if(s.count(a)) A.insert(a);
	}
	cout<<A.size()<<" "<<B.size()<<"\n";
	for(auto x:A) cout<<x<<"\n";
	for(auto x:B) cout<<x<<"\n";
}
accuracy: 1
time_ms: 90
memory_kb: 20288
final_rank: 8

code_snippet: #include <iostream>
#include <set>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;
int main(){
  int a,b;cin>>a>>b;
  map<int,int> A;
  for(int i = 0; a+b > i; i++){
    int t;cin>>t;
    A[t]++;
  }
  vector<int> an;
  vector<int> o;
  for(auto x:A){
    if(x.second == 2){
      an.push_back(x.first);
    }
    o.push_back(x.first);
  }
  cout << an.size() << " " << o.size() << endl;
  sort(an.begin(),an.end());
  sort(o.begin(),o.end());
  for(int i = 0; an.size() > i; i++){
    cout << an[i] << endl;
  }
  for(int i = 0; o.size() > i; i++){
    cout << o[i] << endl;
  }

}
accuracy: 1
time_ms: 250
memory_kb: 14152
final_rank: 13

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

using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main() {
  ll n, m;
  cin >> n >> m;
  map<ll, int> a, b;

  for (int i = 0; i < n; i += 1) {
    int ai;
    cin >> ai;
    a[ai] = 1;
  }
  for (int i = 0; i < m; i += 1) {
    int bi;
    cin >> bi;
    b[bi] = 1;
  }

  map<ll, int> aOrB;
  for (auto ai: a)
    aOrB[ai.first] = 1;
  for (auto bi: b)
    aOrB[bi.first] = 1;

  map<ll, int> aAndB;
  for (auto ai: a)
    if (b[ai.first] == 1) aAndB[ai.first] = 1;

  ll andCnt = 0;
  for (auto andi: aAndB)
    andCnt += 1;
  ll orCnt = 0;
  for (auto ori: aOrB)
    orCnt += 1;

  cout << andCnt << ' ' << orCnt << endl;
  for (auto andi: aAndB) {
    cout << andi.first << endl;
  }
  for (auto ori: aOrB) {
    cout << ori.first << endl;
  }
}
accuracy: 1
time_ms: 350
memory_kb: 39264
final_rank: 20

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

#define int ll
#define rep(i, N) for(int i = 0; i < N; i++)
#define per(i, N) for(int i = N-1; i >= 0; i--)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define TakAo(ans) ans ? cout << "Takahashi\n" : cout << "Aoki\n"
#define YesNo(ans) ans ? cout << "Yes\n" : cout << "No\n"
#define yesno(ans) ans ? cout << "yes\n" : cout << "no\n"
#define equal(f1, f2) (abs(f1 - f2) <= EPS)
#define endl '\n'
#define fi first
#define se second
#define pb push_back
#define mkpr make_pair
#define mktpl make_tuple

using namespace std;
using ll = int64_t;
using ld = long double;
using P = pair<int, int>;
using Tpl = tuple<int, int, int>;
using vvec = vector<vector<int>>;
using vvvec = vector<vector<vector<int>>>;

const ld EPS = 1e-8;
const ld Pi = acos(-1);
const ll INF = 1e9+10;
const int MOD = 998244353;
//const int MOD = 1e9+7;
const int NIL = -1;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, -1, 0, 1};

ll cel(ll a, ll b){ return (a + b - 1) / b; }
ll Gcd(ll a, ll b){ return b ? Gcd(b, a % b) : a; }
ll Lcm(ll a, ll b){ return a / Gcd(a, b) * b; }
ll sq(ll a){ return a * a; }
ll cube(ll a){ return a * a * a; }
ll powi(ll a, ll b){ ll res = 1; rep(i, b) res *= a; return res; }
template<class T> bool chmin(T &a, T b){ if(a > b){ a = b; return 1;} return 0; }
template<class T> bool chmax(T &a, T b){ if(a < b){ a = b; return 1;} return 0; }

void Main(){
	int N, M; cin >> N >> M;
	int a;
	map<int, int> mp;

	rep(i, N){
		cin >> a;
		mp[a]++;
	}
	rep(i, M){
		cin >> a;
		mp[a]++;
	}

	queue<int> AND, OR;
	for(auto it : mp){
		OR.push(it.fi);
		if(it.se > 1) AND.push(it.fi);
	}

	cout << AND.size() << " " << OR.size();
	if(!AND.empty()) cout << endl;


	while(!AND.empty()){
		cout << AND.front();
		AND.pop();
		if(!AND.empty()) cout << endl;
	}
	if(!OR.empty()) cout << endl;

	while(!OR.empty()){
		cout << OR.front();
		OR.pop();
		cout << endl;
	}
}

signed main(){
    cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
    return 0;
}
accuracy: 1
time_ms: 70
memory_kb: 18596
final_rank: 6

code_snippet: #pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>

#define _overload(_1, _2, _3, _4, name, ...) name
#define _rep1(Itr, N) _rep3(Itr, 0, N, 1)
#define _rep2(Itr, a, b) _rep3(Itr, a, b, 1)
#define _rep3(Itr, a, b, step) for (i64 Itr = a; Itr < b; Itr += step)
#define repeat(...) _overload(__VA_ARGS__, _rep3, _rep2, _rep1)(__VA_ARGS__)
#define rep(...) repeat(__VA_ARGS__)

#define ALL(X) begin(X), end(X)

using namespace std;
using i64 = long long;
using u64 = unsigned long long;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    i64 n, m;
    cin >> n >> m;
    vector<i64> a(n), b(m);
    for (auto &vs : a) cin >> vs;
    for (auto &vs : b) cin >> vs;

    set<i64> ast, bst, orst, andst;
    for (auto vs : a) {
        ast.insert(vs);
        orst.insert(vs);
    }
    for (auto vs : b) {
        bst.insert(vs);
        orst.insert(vs);
    }

    for (auto vs : a) {
        if (bst.find(vs) != bst.end()) andst.insert(vs);
    }

    cout << andst.size() << ' ' << orst.size() << endl;
    for (auto vs : andst) {
        cout << vs << '\n';
    }
    for (auto vs : orst) {
        cout << vs << '\n';
    }

    return 0;
}
accuracy: 1
time_ms: 110
memory_kb: 27684
final_rank: 12

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

// template {{{
using i32 = int;
using u32 = unsigned int;
using i64 = long long;
using u64 = unsigned long long;

#define  range(i, l, r) for (i64 i = (i64)(l); i < (i64)(r); (i) += 1)
#define rrange(i, l, r) for (i64 i = (i64)(r) - 1; i >= (i64)(l); (i) -= 1)

#define  whole(f, x, ...) ([&](decltype((x)) container) { return (f)(  begin(container),  end(container), ## __VA_ARGS__); })(x)
#define rwhole(f, x, ...) ([&](decltype((x)) container) { return (f)( rbegin(container), rend(container), ## __VA_ARGS__); })(x)

#define debug(x) cerr << "(" << __LINE__ << ")" << #x << ": " << (x) << endl

constexpr i32 inf   = 1001001001;
constexpr i64 infll = 1001001001001001001ll;

constexpr i32 dx[] = {0, -1, 1, 0, -1, 1, -1, 1}; 
constexpr i32 dy[] = {-1, 0, 0, 1, -1, -1, 1, 1};

struct IoSetup { IoSetup(i32 x = 15){ cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(x); cerr << fixed << setprecision(x); } } iosetup;

template <typename T = i64> T input() { T x; cin >> x; return x; }

template <typename T> ostream &operator<<(ostream &os, vector<T> &v) { range(i, 0, v.size()) { os << v[i] << (i + 1 != (int)v.size() ? " " : ""); } return os; } 
template <typename T> istream &operator>>(istream &is, vector<T> &v) { for (T &in : v) is >> in; return is; }

template <typename T1, typename T2> ostream &operator<<(ostream &os, pair<T1, T2> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
template <typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.first >> p.second; return is; }

template <typename T> vector<T> make_vector(size_t a, T b) { return vector<T>(a, b); }
template <typename... Ts> auto make_vector(size_t a, Ts... ts) { return vector<decltype(make_vector(ts...))>(a, make_vector(ts...)); }

template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }
// }}}

void solve() {
  int n = input(), m = input();

  vector< int > as(n), bs(m);
  cin >> as >> bs;

  set< int > st;
  for (auto &a : as) st.insert(a);

  vector< int > a;
  for (auto &b : bs) {
    as.emplace_back(b);
    if (not st.count(b)) continue;
    a.emplace_back(b);
  }

  whole(sort, as);
  as.erase(whole(unique, as), as.end());

  cout << a.size() << " " << as.size() << endl;
  for (auto &v : a) cout << v << endl;
  for (auto &v : as) cout << v << endl;

}

signed main() {
  solve();
}
accuracy: 1
time_ms: 210
memory_kb: 12220
final_rank: 11

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

#define For(i, a, b) for (int(i) = (int)(a); (i) < (int)(b); ++(i))
#define rFor(i, a, b) for (int(i) = (int)(a)-1; (i) >= (int)(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second

using namespace std;

typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> pii;
typedef pair<lint, lint> pll;

template <class T>
bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template <class T>
bool chmin(T &a, const T &b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}

template <class T>
T div_floor(T a, T b) {
    if (b < 0) a *= -1, b *= -1;
    return a >= 0 ? a / b : (a + 1) / b - 1;
}
template <class T>
T div_ceil(T a, T b) {
    if (b < 0) a *= -1, b *= -1;
    return a > 0 ? (a - 1) / b + 1 : a / b;
}

template <typename T>
struct coord_comp {
    vector<T> v;
    bool sorted = false;

    coord_comp() {}

    int size() { return v.size(); }

    void add(T x) { v.push_back(x); }

    void build() {
        sort(v.begin(), v.end());
        v.erase(unique(v.begin(), v.end()), v.end());
        sorted = true;
    }

    int get_idx(T x) {
        assert(sorted);
        return lower_bound(v.begin(), v.end(), x) - v.begin();
    }
};

constexpr lint mod = 1000000007;
constexpr lint INF = mod * mod;
constexpr int MAX = 200010;

int main() {
    int n, m;
    scanf("%d%d", &n, &m);
    vector<int> a(n), b(m);
    rep(i, n) scanf("%d", &a[i]);
    rep(i, m) scanf("%d", &b[i]);

    vector<int> and_ans;
    rep(i, n) {
        auto it = lower_bound(b.begin(), b.end(), a[i]);
        if (it != b.end() && *it == a[i]) and_ans.push_back(a[i]);
    }

    set<int> or_ans;
    rep(i, n) or_ans.insert(a[i]);
    rep(i, m) or_ans.insert(b[i]);

    printf("%d %d\n", and_ans.size(), or_ans.size());
    for (auto x : and_ans) printf("%d\n", x);
    for (auto x : or_ans) printf("%d\n", x);
}
accuracy: 1
time_ms: 60
memory_kb: 14440
final_rank: 4

code_snippet: #include <iostream> 
#include<vector>
#include<algorithm>
#include<map>
#include<string>
#include<iomanip>
#include<set>
#include<queue>
#include<deque>
#include<sstream>
#include<cmath>
#include<bitset>
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define req(i,n) for(int i = 1;i <=  n; i++)
#define rrep(i,n) for(int i = n-1;i >= 0;i--)
#define ALL(obj) begin(obj), end(obj)
#define RALL(a) rbegin(a),rend(a)
typedef long long int ll;
typedef long double ld;
template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T& val) {
    std::fill((T*)array, (T*)(array + N), val);
}
const int MAX = 510000;
const int MOD = 1000000007;
const int inf = 1<<31-1;
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; }
int main(void) {
    int n, m; cin >> n >> m; vector<int> a(n), b(m),o;
    set<int> st;
    rep(i, n) {
        cin >> a[i]; st.insert(a[i]);
    }rep(i, m) {
        cin >> b[i]; st.insert(b[i]);
        if (binary_search(ALL(a), b[i])) o.push_back(b[i]);
    }cout << o.size() << " " << st.size() << endl;
    for (int i : o) cout << i << endl;
    for (int i : st)cout << i << endl;
}
accuracy: 1
time_ms: 310
memory_kb: 13980
final_rank: 15

code_snippet: #include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,-1,0,1,1,-1,1,-1};
template<class T> inline bool chmin(T& a, T b) {
    if (a >= b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}


int main(){
    ll n,m;cin >> n >>m;
    set<ll> AND,OR,A;
    rep(i,n){
        ll a;cin >> a;
        A.ins(a),OR.ins(a);
    }
    rep(i,m){
        ll b;cin >> b;
        if(A.count(b))AND.insert(b);
        OR.insert(b);
    }
    cout << AND.size() <<" " << OR.size() <<endl;
    for(auto p:AND)cout << p <<endl;
    for(auto z:OR)cout << z <<endl;
}
accuracy: 1
time_ms: 350
memory_kb: 20024
final_rank: 18

code_snippet: #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;
}
accuracy: 1
time_ms: 370
memory_kb: 25912
final_rank: 19

code_snippet: #include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
int arr[200001], arr2[200001], arr3[400001], reps[200001];

int main()
{
    int n, m, len, s1, s2, idx, idx2;
    scanf("%d %d", &n, &m);

    for (int i = 0; i < n; i++) scanf("%d", &arr[i]);
    for (int i = 0; i < m; i++) scanf("%d", &arr2[i]);

    len = n + m, s1 = s2 = idx = idx2 = 0;
    while (s1 < n && s2 < m) {
        if (arr[s1] == arr2[s2]) { reps[idx2++] = arr[s1]; arr3[idx++] = arr[s1++]; s2++; }
        else if (arr[s1] < arr2[s2]) arr3[idx++] = arr[s1++];
        else if (arr2[s2] < arr[s1]) arr3[idx++] = arr2[s2++];
    }
    if (s1 <= n - 1) while (s1 < n) arr3[idx++] = arr[s1++];
    if (s2 <= m - 1) while (s2 < m) arr3[idx++] = arr2[s2++];
    printf("%d %d\n", idx2, len - idx2);
    for (int i = 0; i < idx2; i++) printf("%d\n", reps[i]);
    for (int i = 0; i < idx; i++) printf("%d\n", arr3[i]);
     return 0;
}
accuracy: 1
time_ms: 30
memory_kb: 4616
final_rank: 1

code_snippet: #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;
    }
}
accuracy: 1
time_ms: 280
memory_kb: 5080
final_rank: 10

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1e16;
const ll mod = 1000000007;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

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;
}
int ctoi(char c) {
  if (c >= '0' && c <= '9') {
    return c - '0';
  }
  return 0;
}
ll factorial(ll n) {
  if (n == 1) {
    return 1;
  }
  ll ans = factorial(n-1);
  return ans*n;
}
ll gcd(ll a, ll b) {
  if (b == 0) return a;
  return gcd(b, a%b);
}
ll lcm(ll a, ll b) {
  return (a/gcd(a, b))*b;
}
bool is_prime(ll n) {
  for (ll i = 2; i*i <= n; i++) {
    if (n%i == 0) return false;
  }
  return n != 1;
}
ll mod_pow(ll x, ll n, ll mod) {
  if (n == 0) return 1;
  ll res = mod_pow(x*x%mod, n/2, mod);
  if (n & 1) res = res * x % mod;
  return res;
}

int main() {
  ll n, m;
  cin >> n >> m;
  set <ll> s;
  vector <ll> v;
  ll a;
  rep(i, n) {
    cin >> a;
    s.insert(a);
  }
  rep(i, m) {
    cin >> a;
    if (s.count(a)) {
      v.push_back(a);
    } else {
      s.insert(a);
    }
  }
  sort(v.begin(), v.end());
  cout << v.size() << ' ' << s.size() << endl;
  rep(i, v.size()) {
    cout << v.at(i) << endl;
  }
  for (auto value : s) {
    cout << value << endl;
  }
}
accuracy: 1
time_ms: 310
memory_kb: 13240
final_rank: 14

code_snippet: #include<iostream>
#include<string>
#include<iomanip>
#include<cmath>
#include<vector>
#include<algorithm>
#include<map>

using namespace std;

#define int long long
#define rep(i,n) for(int i = 0; i < (n); i++)
#define INF ((long long)1e18)
#define MOD ((int)1e9+7)
#define endl "\n"

#define yn(f) ((f)?"Yes":"No")
#define YN(f) ((f)?"YES":"NO")

#define MAX

signed main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);
	
	map<int,int> mp;
	int a, b, n, m;
	vector<int> c, d;
	
	cin>>n>>m;
	
	
	for(int i = 0; i < n; i++){
		cin>>a;
		mp[a]++;
	}
	for(int i = 0; i < m; i++){
		cin>>a;
		mp[a]++;
	}
	
	for(pair<int,int> t : mp){
		if(t.second == 2) d.push_back(t.first);
		c.push_back(t.first);
	}
	
	cout<<d.size()<<" "<<c.size()<<endl;
	
	for(int i = 0; i < d.size(); i++){
		cout<<d[i]<<endl;
	}
	for(int i = 0; i < c.size(); i++){
		cout<<c[i]<<endl;
	}
	
	return 0;
}
accuracy: 1
time_ms: 70
memory_kb: 18720
final_rank: 7