1 # include <stdio.h>
 2 # include <malloc.h>
 3 # include <string.h> 
 4 typedef struct node 
 5 {
 6  struct node *next;
 7  struct node *prior;
 8  int data;
 9 }LINK;
10 int main()
11 {
12  int i,j,k,n,m;
13  LINK *q,*p,*tail,*head;
14  head=(LINK *)malloc(sizeof(LINK));
15  head->next=NULL;
16  head->prior=NULL;
17  tail=head;
18  scanf("%d%d",&n,&m);
19  for(i=0;i<n;i++)
20  {
21   p=(LINK *)malloc(sizeof(LINK));
22   scanf("%d",&p->data);
23   tail->next=p;
24   p->prior=tail;
25   tail=p;
26  }
27  tail->next=NULL;
28  while(m--)
29  {
30   scanf("%d",&j);
31   p=head->next;
32   for(i=0;i<n;i++)
33   {
34    if(p->data == j)
35    {
36     if(p->prior->prior != NULL)
37      printf("%d ",p->prior->data);
38     if(p->next != NULL)
39      printf("%d",p->next->data);
40    }
41    p=p->next; 
42   }
43   printf("\n");
44  }
45  return 0;
46 }