#include <stdio.h> 
#include <stdlib.h>
struct node {
    int data;
    struct node* next;
};
int main() {
    int n, x, i, val;
    stuct node *head = NULL, *temp, *prev , *last = NULL *lastprev = NULL;
    scanf("%d", &n);
    if (n <= 0) {
        printf("Invalid input");
        return 0;
    }
    for (i = 0; i < n; i++) {
        scanf("%d", &val);
        struct node* new = (struct node*)malloc(sizeof(struct node));
        new->data = val;
        new->next = NULL;
        if (!head)
           head = temp = new;
           else {
               temp->next = new;
               temp = new;
           }
    }
    scanf("%d", &x);
    temp = head; prev = NULL;
    while (temp && temp->data !=x) {
        prev = temp;
        temp = temp->next;
    }
    if (!temp){
        printf("elements not found");
        return 0;
    }
    if (!prev) head = temp->next;
    else prev->next = temp->next;
    free(temp);
    temp = head; prev = NULL;
    while (temp) {
        if (temp->data == x) {
            last = temp;
            lastprev= prev;
        }
        if (last) {
            if (!lastprev) head = last->next;
            elase lastprev->next = last->next;
            free(last);
        }
        temp = head;
        while (temp) {
            printf("%d ", temp->data);
            temp = temp->next;
        }
    return 0;
}