#include<stdio.h>
#include<stdlib.h>
struct Node {
    int data;
    struct Node*next;
};
struct Node*createNode(int value){
    struct Node* newNode=(struct Node*)malloc(sizeof(struct Node));
    newNode->data=value;
    newNode->next=NULL;
    return newNode;
}
void append(struct Node** head,int value) {
    struct node*newNode = createNode(value);
    if(*head==NULL {
        *head=newNode;
        return;
    }
    struct Node*temp = *head;
    while(temp->next !=NULL) {
        temp = temp->next;
    }
    temp->next = newNode;
    }
    void deletelastx(struct Node**head,int k){
        if(*head==NULL) return {
            int length=0;
            struct Node*temp=*head;
            while(temp 1=NULL) {
                length++;
                temp=temp->next;
            }
            if(k == length){
                *head=NULL;
                printf("List is empty\n");
            }
            int stop=length-k-1;
            temp=*head;
            for(int i=0;i < stop + 1; i++){
                if(temp->Next == NULL) break;
                if (i == stop) break;
                temp =temp->next;
            }
            struct Node*del =temp->next;
            temp->next=NULL;
            while(del !=NULL) {
                struct Node*next=del->next;
                free(del);
                del=next;
            }
            struct Node* curr=*head;
            while(curr !=NULL) {
                printf("%d",curr->data);
                if(curr->next !=NULL)printf(" ");
                curr=curr->next;
            }
            printf("\n");
        }
        int main(){
            int n;
            if(scanf("%d",&n)!=1||n<1||n>1000) {
                printf("Invalid input\n");
                return 0;
            }
            deleteLastx(&head,k);
            return 0;
        }