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

#define int long long

signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  int N;
  int H, W;  
  string s;

  cin >> N;

  int M;
  cin >> M;
  
  vector<int> A(N, 0);
  vector<int> B(N, 0);  
  int ans = 0;

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

  int ans1 = 0, ans2 = 0;  
  for ( pair<int, int> a : c ) {
    if ( a.second == 2 ) ans1++;    
  }

  for ( pair<int, int> a : c ) {
    if ( a.second >= 1 ) ans2++;    
  }

  cout << ans1 << " " << ans2 << endl;
  for ( pair<int, int> a : c ) {
    if ( a.second == 2 ) cout << a.first << endl; 
  }

  for ( pair<int, int> a : c ) {
    if ( a.second >= 1 ) cout << a.first << endl;
  }
  
  return 0;
}

