//editor2
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

// Define the structure for a node in the doubly linked list
typedef struct Node {
    char chapterName[100];
    struct Node* prev;
    struct Node* next;
} Node;

// Global head pointer for the list
Node* head = NULL;

// Function to create a new node
Node* createNode(const char* name) {
    Node* newNode = (Node*)malloc(sizeof(Node));
    if (newNode == NULL) {
        exit(1);
    }
    strcpy(newNode->chapterName, name);
    newNode->prev = NULL;
    newNode->next = NULL;
    return newNode;
}

// Function to insert a node at the end of the list
void insertEnd(const char* name) {
    Node* newNode = createNode(name);
    if (head == NULL) {
        head = newNode;
        return;
    }
    Node* temp = head;
    while (temp->next != NULL) {
        temp = temp->next;
    }
    temp->next = newNode;
    newNode->prev = temp;
}

// Function to delete a node at a given position (0-based)
void deleteNodeAtPosition(int pos) {
    // Traverse to the node at the specified position
    Node* current = head;
    int count = 0;
    while (current != NULL && count < pos) {
        current = current->next;
        count++;
    }

    // If the node is not found, or pos is out of bounds
    if (current == NULL) {
        printf("Invalid input.\n");
        return;
    }

    // Deleting the head node
    if (current->prev == NULL) {
        head = current->next;
        if (head != NULL) {
            head->prev = NULL;
        }
    }
    // Deleting a middle or last node
    else {
        current->prev->next = current->next;
        if (current->next != NULL) {
            current->next->prev = current->prev;
        }
    }
    free(current);
}

// Function to print the list in the required format
void printUpdatedList() {
    if (head == NULL) {
        printf("List is empty.\n");
        return;
    }
    Node* temp = head;
    while (temp != NULL) {
        printf("%s", temp->chapterName);
        if (temp->next != NULL) {
            printf(" ");
        }
        temp = temp->next;
    }
    printf("\n");
}

// Function to free all nodes and clean up memory
void freeList() {
    Node* temp;
    while (head != NULL) {
        temp = head;
        head = head->next;
        free(temp);
    }
}

int main() {
    int n, pos;

    // Read the number of bookmarked chapters
    scanf("%d", &n);

    // Read the line of chapter names
    for (int i = 0; i < n; i++) {
        char chapterName[100];
        scanf("%s", chapterName);
        insertEnd(chapterName);
    }

    // Read the position to delete
    scanf("%d", &pos);

    // Handle invalid input: pos >= n
    if (pos >= n || pos < 0) {
        printf("Invalid input.\n");
    } else {
        deleteNodeAtPosition(pos);
        printUpdatedList();
    }