#include<stdio.h>
#include<stdlib.h>

struct Node{
    int data;
    struct Node* next;
};
struct Node* createNode(int data){
    struct Node*newNode=(struct Node*)malloc(sizeof(struct Node));
    newNode->data = data;
    newNode->next = NULL;
    return newNode;
}
struct Node* deleteNode(struct Node* head,int x){
    struct Node *temp = head,*prev = NULL;
    if(temp != NULL && temp->data == x){
        head = temp->next;
        free(temp);
        return head;
    }
    while(temp != NULL && temp->data != x)
    {
        prev = temp;
        temp = temp->next;
    }
    if(temp == NULL){
        printf("Node not found");
        return NULL;
    }
    prev->next = temp->next;
    free(temp);
    return head;
}
struct Node* temp = head;
while (temp != NULL){
    printf("%d", temp->data);
    if(temp->next != NULL)
    printf(" ");
    temp = temp->next;

}
int main(){
    int n,x;
    scanf("%d",&n);
    struct Node *head=NULL,*tail=NULL;
    for(int i=0;i<n;i++){
        int val;
        scanf("%d", &val);
        struct Node* newNode = createNode(val);
        if(head == NULL)
        head = tail = newNode;
        else{
            tail->next = newNode;
            tail = newNode;
        }
    }
    scanf("%d",&x);
    struct Node* result = deleteNode(head,x);
    if(result == NULL && head != NULL)
    return 0;
    printList(result);
    return 0;
}