#include<stdio.h>
#include<stdlib.h>
struct Node{
    int data;
    struct Node*next;
};
struct Node*head=NULL;
void isertAtEnd(int val){
    struct Node*newNode=(struct Node*)malloc(sizeof(struct Node));
    newNode->data=val;
    newNode->next=NULL;
    if(head==NULL){
        head=newNode;
    }
    else{
        struct Node*temp=head;
        while(temp->next!=NULL)
        temp=temp->next;
        temp->next=newNode;
    }
}
void deleteLast(int k,int n){
    if(k>n){
        printf("invalid input\n");
        exit(0);
    }
    if(k==n){
        printf("list is empty\n");
        exit(0);
    }
    int stop=n-k;
    struct Node*temp=head;
    for(int i=1;i<stop;i++)
    {
        temp=temp->next;
    }
    struct Node*temp=head;
    while(temp!=NULL){
        printf("%d",temp->data);
        if(temp->next!=NULL)
        printf(" ");
        temp=temp->next;
    }
    print("\n");
}
int main(){
    int n,k,val;
    scanf("%d\n",&val);
    for(int i=0;i<n;i++)
    {
        scanf("%d\n",&val);
        insertAtEnd(val);
    }
    scanf("%d",&k);
    deleteLast(kn);
    display();
    return 0;
}