// editor5
#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));
    if(newNode == NULL){
        printf("Memory allocation failed\n");
        exit(1);
    }
    newNode->data = data;
    newNode->next = NULL;
    return newNode;
}
void printList(struct Node* head){
    struct Node* current = head;
    if(current == NULL){
        return;
    }
    while (current != NULL){
        printf("%d ",current->data);
        current = current->next;
    }
    printf("\n");
}

void deleteNode(struct Node** head_ref,int position){
    if(*head_ref == NULL){
        printf("Invalid input\n");
        return;
    }
    if(position == 0){
        struct Node* temp = *head_ref;
        *head_ref = temp->next;
        free(temp);
        return;
    }
    struct Node* current = *head_ref;
    for(int i = 0;current != NULL && i<position - 1;i++){
        current = current->next;
    }
    if(current == NULL || current->next == NULL){
        printf("Invalid input\n");
        return;
    }
    struct Node* node_to_delete ->next;
    current->next = node_to_delete ->next;
    free(node_to_delete);
}
int main(){
    int N,P;
    if(scanf("%d",&N) != 1){
        return 1;
    }
    if(N<0||N>100){
        printf("Invalid input\n");
        return 0;
    }
    struct Node*head = NULL;
    struct Node*tail= NULL;
    
    if(N>0){
        for (int i=0;i<N;i++){
            int data;
            if(scanf("%d",&data)!= 1){
                return 1;
            }
            if(data<1 || data>1000){
                printf("Invalid input\n");
                
                struct Node* temp;
                while(head != NULL){
                    temp = head;
                    head =head->next;
                    free(temp);
                }
                return 0;
            }
            struct Node* newNode = createNode(data);
            if(head == NULL){
                head = newNode;
                tail = newNode;
                }else{
                    tail->next = newNode;
                    tail = newNode;
                }
            }
        }
        if(scanf("%d",&P)!= 1){
            return 1;
        }
        if(P<0||P>=N){
            printf("Invalid input\n");
            struct Node*temp;
            while (head != NULL){
                temp = head;
                head = head->next;
                free(temp);
            }
            return 0;
        }
        deleteNode(&head,P);
        printList(head);
        struct Node* temp;
        while(head != NULL){
            temp = head;
            head = head->next;
            free(temp);
        }
        return 0;
    }