#include
struct Node{
int num;
struct Node *next;
};
struct Node *read();
void comp(struct Node *n,struct Node *m);
int main(){
struct Node *a,*b;
a=read();
b=read();
comp(a,b);
}
struct Node *read(){
int flag=1;
struct Node *head,*a,*b;
a=head=malloc(sizeof(struct Node));
head->next=NULL;
scanf("%d",&a->num);
if(a->num == -1) head=NULL;
while(a->num != -1){
if(flag != 1){
b=malloc(sizeof(struct Node));
b->next=NULL;
a->next=b;
a=b;
scanf("%d",&a->num);
}
else
flag = 0;
}
return head;
}
void comp(struct Node *n,struct Node *m){
int flag=1;
struct Node *a,*b,*n_head,*c;
if(n !=NULL && m != NULL)
while(n->num != -1 || m->num != -1)
{
if(n->num == m->num)
{
if(flag==1)
{
n_head=n;
n=n->next;
a=n_head;
flag=0;
}
else{
a->next=n;
a=n;
n=n->next;
a->next = NULL;
}
m=m->next;
}
else if(n->num == -1 || m->num == -1)
break;
else if(n->num < m->num)
n=n->next;
else if(n->num > m->num)
m=m->next;
}
else
{
printf("NULL");
return 0;
}
b=n_head;
while(b)
{
if(b->num == -1){printf("NULL");break;}
printf("%d",b->num);
if(b->next != NULL)
printf(" ");
b=b->next;
}