#include <stdio.h>
#include <stdlib.h>
typedef struct Node{
    int data;
    struct Node* prev;
    struct Node* next;
}Node;

Node *head=NULL, *tail, *temp, *temp2, *sorted, *curr;

void create(int num){
    Node *new = (Node*)malloc(sizeof(Node));
    new->data=num;
    new->next=NULL;
    new->prev=NULL;
    
    if(head==NULL){
        head = new;
        tail = new;
    }
    else{
        new->prev = tail;
        tail->next = new;
        tail = new;
    }
}

void sort(){
    sorted = NULL;
    temp = head;
    
    while(curr!=NULL){
        temp2 = temp->next;
        if(sorted==NULL || sorted->data>=temp->data){
            temp->next=sorted;
            if(sorted!=NULL){
                sorted->prev = temp;
            }
            sorted = temp;
            sorted->prev=NULL;
        }
        else{
            curr = sorted;
            while(curr->next !=NULL && curr->next->data<temp->data){
                curr = curr->next;
            }
            temp->next = curr->next;
            if(curr->next !=NULL){
                curr->next->prev = curr;
            }
            curr->next = temp;
            temp->prev = curr;
        }
        temp = temp2;
    }
}

void display(){
    Node *i;
    for(i=head;i!=NULL;i=i->next){
        printf("%d",i->data);
    }
}

int main(){
    
    // for(i=0;i<n;i++){
    //     if(!(scanf("%d",&num))){
    //         printf("Invalid input");
    //         return 0;
    //     }
    //     create(num);
    // }
    
    
    // for(i=0;i<m;i++){
    //     if(!(scanf("%d",&num))){
    //         printf("Invalid input");
    //         return 0;
    //     }
    //     create(num);
    // }
    // sort();
    // display();
    // return 0;
    int n,m,i,j,temp;
    scanf("%d",&n);
    if(n<=0){
        printf("Invalid input");
        return 0;
    }
    
    int arr[n];
    for(i=0;i<n;scanf("%d",&arr[i++]));
    
    scanf("%d",&m);
    if(m<=0){
        printf("Invalid input");
        return 0;
    }
    m+=n;
    for(i=n;i<m;scanf("%d",&arr[i++]));
    
    for(i=0;i<m-1;i++){
        for(j=0;j<m-i-1;j++){
            if(arr[j]>arr[j++]){
                temp = arr[j];
                arr[j] = arr[j++];
                arr[j++] = temp;
            }
        }    
    }
    printf("%d %d\n"n,m);
    for(i=0;i<m;printf("%d ",arr[i++]));
}