#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>

struct Node {
    int data;
    struct Node* next;
};

struct Node* head = NULL;
struct Node* tail = NULL;

void addNode(int value) {
    struct Node* newNode = (struct Node*)malloc(sizeof(struct Node));
    newNode->data = value;
    newNode->next = NULL;

    if (head == NULL) {
        head = tail = newNode;
    } else {
        tail->next = newNode;
        tail = newNode;
    }
}

int deleteValue(int val) {
    struct Node* temp = head;
    struct Node* prev = NULL;

    while (temp != NULL) {
        if (temp->data == val) {
            if (prev == NULL) { 
                head = head->next;
                if (head == NULL) tail = NULL; 
            } else {
                prev->next = temp->next;
                if (temp == tail) tail = prev; 
            }
            free(temp);
            return 1; 
        }
        prev = temp;
        temp = temp->next;
    }
    return 0;
}

void printList() {
    if (head == NULL) {
        printf("List is empty");
        return;
    }
    struct Node* temp = head;
    while (temp != NULL) {
        printf("%d", temp->data);
        if (temp->next != NULL) printf(" ");
        temp = temp->next;
    }
}

int main() {
    int n;
    if (scanf("%d", &n) != 1 || n < 0 || n > 1000) {
        printf("Invalid input");
        return 0;
    }

    for (int i = 0; i < n; i++) {
        int value;
        if (scanf("%d", &value) != 1) {
            printf("Invalid input");
            return 0;
        }
        addNode(value);
    }

    int val;
    if (scanf("%d", &val) != 1) {
        printf("Invalid input");
        return 0;
    }

    if (deleteValue(val)) {
        printList();
    } else {
        printf("Value not found");
    }

    return 0;
}