#include<stdio.h>
#include<stdlib.h>
struct node{
    int data;
    struct node*next;
};
struct node*createnode(int value){
    struct node*newnode=(struct node*)malloc(size of(struct node))
    newnode->data=value;
    newnode->next=NULL;
    return newnode;
}
void deleteLastK(struct node*head,int K){
    int len=0;
    struct node*temp=*head;
    while(temp!=NULL){
        len++;
        temp=temp->next;
    }
    if(K==len){
        printf("List is empty\n");
        return;
    }
    int stop=len-K;
    temp=*head;
    for(int i=1;i<stop;i++){
        temp=temp->next;
    }
    struct node*del=temp->next;
    temp->next=NULL;
    while(del!=NULL){
        struct node*t=del;
        del=del->next;
        free(t);
    }
    temp=*head;
    while(temp!=NULL){
        printf("%d",temp->data);
        if(temp->next !=NULL) printf(" ");
        temp=temp->next;
    }
    printf("\n");
}
int main(){
    int n;
    scanf("%d",&n);
    struct node*head=NULL;
    struct node*tail=NULL;
    
    for(int i=0;i<n;i++){
        int id;
        scanf("%d",&id);
        struct node*newnode=createnode(id);
        if(head==NULL){
            head=newnode;
            tail=newnode;
        }
        else{
            tail->next=newnode;
            tail=newnode;
        }
    }
    int K;
    scanf("%d",&K);
    
    if(head->next==NULL&&K==1){
        printf("List is empty\n");
        return 0;
    }
    deleteLastK(&head,K);
    struct node*temp=head;
    while(temp!=NULL){
        struct node*t=temp;
        temp=temp->next;
        free(t);
    }
    return 0;
}