#include<iostream>
#include<vector>
using namespace std;

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

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

    vector<int> resa, resb;
    
    int i = 0, j = 0;
    while( i < n && j < m )
    {
        if( a[i] == b[j] )
        {
            resa.push_back( a[i] );
            resb.push_back( a[i] );
            i++; j++;
            continue;
        }
        else if( a[i] < b[j] )
        {
            resb.push_back( a[i] );
            i++;
        }
        else
        {
            resb.push_back( b[j] );
            j++;
        }
    }

    while( i < n )
        resb.push_back( a[i++] );
    while( j < m )
        resb.push_back( b[j++] );

    cout << resa.size() << " " << resb.size() << endl;
    
    for( int k = 0; k < resa.size(); k++ )
        cout << resa[k] << endl;
    
    for( int k = 0; k < resb.size(); k++ )
        cout << resb[k] << endl;

    return 0;
}
