#include<stdio.h>
#include<stdlib.h>
struct node *first,*second;
typedef struct node{
    int data;
    struct node *next;
}node;
node *head=NULL,*tail;

void create(int num){
    node *newnode=(node*)malloc(1*sizeof(node));
    newnode->data=num;
    newnode->next=NULL;
    if(head==NULL){
        head=newnode;
        tail=newnode;
    }
    else{
        tail->next=newnode;
        tail=newnode;
    }
}

void del(int pos){
    first=head;
    second=head->next;
    if(pos==head->data){
        head=head->next
    }
    else{
        while(second!=NULL){
            if(second->data==pos){
                first->next=second->next;
                break;
            }
            first=first->next;
            second=second->next;
        }
    }
}
void display(){
    node *i;
    for(i=head;i!=NULL;i=i->next){
        printf("%d",i->data)
    }
}

int main(){
    int s,n,i,pos;
    scanf("%d",&s);
    if(s<0){
        printf("Invalid input");
        return 0;
    }
    for(i=0;i<s;i++){
        if(!scanf("%d",&n)){
            printf("Invalid input");
            return 0
        }
        create(n);
    }
    scanf("%d",&pos);
    
    display();
    del(pos);
    display();
    return 0;
}