#include<stdio.h>
#include<stdlib.h>
#define len sizeof(struct node)
#define null 0
struct node
{
int x;
struct node*next;
};
int n;
int main()
{
int x;
struct node *head;
struct node *p1,*p2,*p,*a;
struct node*del (struct node*head,int x );
struct node*ins (struct node*head,struct node*x );
n=0;
p1=p2=(struct node*)malloc(len);
scanf("%d",&p1->x);
head=null;
while(p1->x!=0)
{
n++;
if(n==1)head=p1;
else p2->next=p1;
p2=p1;
p1=(struct node*)malloc(len);
scanf("%d",&p1->x);
}
p2->next=null;
p=head;
while(p!=0)
{
printf("%d ",p->x);
p=p->next;
}
scanf("%d",&x);
p=del(head,x);
while(p!=0)
{
printf("%d ",p->x);
p=p->next;
}
return 0;
}
struct node*del (struct node*head,int x )
{
struct node *p1,*p2;
p1=head;
while(x!=p1->x&&p1->next!=null)
{
p2=p1;
p1=p1->next;
}
if(x==p1->x)
{
if(p1==head) head=p1->next;
else p2->next=p1->next;free(p1);
}return (head);
}