#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<ctype.h>
struct Node {
    char data[101];
    struct Node* prev;
    struct Node* Next;
};
struct Node* createNode(char* data){
    struct Node* newNode = (struct Node*)malloc(sizeof(struct Node));
    strcpy(newNode->data,data);
    newNode->prev = NULL;
    newNode->Next = NULL;
    return newNode;
}
void append(struct Node** head,char* data){
    struct Node* newNode = createNode(data);
    if(head == NULL){
    *head = newNode;
    return ;
    
}
struct Node*temp = *head;
while(temp->Next !=NULL){
    temp=temp->Next;
    
}
temp->next = newNode;
newNode->prev = temp; 
} 
void deleteAtPosition(struct Node* head,int pos,int n){
    if(pos < 0 || pos>=n){
        printf("Invalid input\n");
        exit(0);
    }
    struct Node* temp = *head;
    int index = 0;
    while (temp != NULL && index <pos){
        temp = temp->next
        index ++;
    }
    if(temp == NULL) return ;
    if(temp)->prev == NULL{
        *head = temp->next;
        if(*head !=NULL)(*head)->prev=NULL;
        temp->next->prev = temp->prev;
        
    }
    free(temp);
    
}
void printList(struct Node*head){
    if(head == NULL){
        printf("List is empty\n");
        return ; 
    }
    struct Node*temp= head;
    while (temp !=NULL) {
        printf("%s",temp->data);
        temp = temp ->Next;
        
    }
    printf("\n");
}
int isvalidName(char* str) {
    if(!isalpha(str[0])) return 0;
    for(int i=1;str[i]!='\0';i++){
        if (!isalum(str[i])) return 0;
        
    }
    return 1;
}
int main(){
    int n,pos;
    if (scanf("%d,&n") !=1||n<1||n>1000) {
        printf("Invalid input\n");
        return 0;
    }
    struct Node*head=NULL;
    for (int i=0;i<n;i++){
        char buffer[101];
        if(scanf("%s",buffer)!=1|| !invalidname(buffer)){
            printf("Invalid input\n");
            return 0;
        }
        append(&head,buffer);
    }
    if (scanf("%d",&pos)!=1) {
        printf("Invald input\n");
        return 0;
    }
    deleteAtposition(&head,pos,n);
    printList(head);
    return 0;
    
}