#include <stdio.h>
#include <stdlib.h>
struct Node{
    int data;
    struct Node* next;
};
struct Node* creteNode(int data){
    struct Node* newNode = (struct Node*)malloc(sizeof(struct Node));
    newNode->data = data;
    newNode->next = NULL;
    return newNode;
}
void printLists(struct Node** head, int position){
    if (*head == NULL)
    return;
    struct Node*temp = *head;
    // If deleting the head
    if (position == 0){
        *head = temp->next;
        free(temp);
        return;
    }
// Find previous node of the node to delete
for (int i = 0; temp != NULL && i < position - 1; i++)
temp = temp->next;
// If poisition is invalid
if (temp == NULL || temp->next == NULL)
return;
struct Node*next = temp->next->next;
free(temp->next);
temp->next = next;
}
int main(){
    int N, data, P;
    scanf("%d",&N);
    if(N <= 0){
        printf("Invalid input");
        return 0;
    }
    struct Node*head = NULL;
    struct Node*tail = NULL;
    // Read N elements
    for (int i = 0; i < N, i++){
        if (scanf("%d",&data) != 1){
            return 0;
        }
        struct Node*newNode=createNode(data);
        if (head == NULL)
           head = tail = newNode;
           else {
           tail->next = newNode;
           tail = newNode;
    }
}
// Read position to delete 
if (scanf("%d",&P)!= 1|| P < 0 || P >= N)
        printf("Invalid Input");
        return 0;
    }
    deleteNode(&head,P);
    if (head == NULL)
    printf("Invalid Input");
    else
    printList(head);
    return 0;
    }
}