#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define MAX_LEN 100

// Structure for doubly linked list node
struct Node {
    char name[MAX_LEN];
    struct Node *prev, *next;
};

// Function to create a new node
struct Node* createNode(char *name) {
    struct Node newNode = (struct Node)malloc(sizeof(struct Node));
    strcpy(newNode->name, name);
    newNode->prev = NULL;
    newNode->next = NULL;
    return newNode;
}

// Function to insert node at end
void insertEnd(struct Node **head, char *name) {
    struct Node *newNode = createNode(name);
    if (*head == NULL) {
        *head = newNode;
        return;
    }
    struct Node *temp = *head;
    while (temp->next != NULL)
        temp = temp->next;
    temp->next = newNode;
    newNode->prev = temp;
}

// Function to delete node at given position
int deleteAtPosition(struct Node **head, int pos, int n) {
    if (pos < 0 || pos >= n) return 0; // invalid position

    struct Node *temp = *head;
    int index = 0;

    // Traverse to the position
    while (index < pos) {
        temp = temp->next;
        index++;
    }

    // Update links
    if (temp->prev != NULL)
        temp->prev->next = temp->next;
    else
        *head = temp->next; // deleting head

    if (temp->next != NULL)
        temp->next->prev = temp->prev;

    free(temp);
    return 1; // success
}

// Function to print list
void printList(struct Node *head) {
    if (head == NULL) {
        printf("List is empty\n");
        return;
    }
    struct Node *temp = head;
    while (temp != NULL) {
        printf("%s", temp->name);
        if (temp->next != NULL)
            printf(" ");
        temp = temp->next;
    }
    printf("\n");
}

int main() {
    int n, pos;
    char name[MAX_LEN];
    struct Node *head = NULL;

    // Input number of bookmarks
    scanf("%d", &n);

    // Input chapter names
    for (int i = 0; i < n; i++) {
        scanf("%s", name);
        insertEnd(&head, name);
    }

    // Input position to delete
    scanf("%d", &pos);

    // Deletion and output
    if (!deleteAtPosition(&head, pos, n))
        printf("Invalid\n");
    else
        printList(head);

    return 0;
}