#include <stdio.h>
#include <stdlib.h>

struct node {
    int data;
    struct node* next;
};

struct node* create_node(int val) {
    struct node* newnode = malloc(sizeof(struct node));
    newnode->data = val;
    newnode->next = NULL;
    return newnode;
}

void free_list(struct node* head) {
    while (head) {
        struct node* temp = head;
        head = head->next;
        free(temp);
    }
}

int main() {
    int n, k;
    scanf("%d", &n);

    if (n <= 0) {
        printf("list is empty\n");
        return 0;
    }

    struct node *head = NULL, *tail = NULL;
    for (int i = 0, val; i < n; i++) {
        scanf("%d", &val);
        struct node* newnode = create_node(val);
        if (!head)
            head = tail = newnode;
        else {
            tail->next = newnode;
            tail = newnode;
        }
    }

    scanf("%d", &k);

    if (k < 0 || k > n) {
        printf("Invalid input\n");
        free_list(head);
        return 0;
    }

    if (k == n) {
        free_list(head);
        printf("list is empty\n");
        return 0;
    }

    struct node* curr = head;
    for (int i = 1; i < n - k; i++)
        curr = curr->next;

    free_list(curr->next);
    curr->next = NULL;

    curr = hea