#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define MAX_LEN 100


typedef struct Node {
    char song[MAX_LEN];
    struct Node *next;
} Node;


Node* createNode(char *song) {
    Node newNode = (Node)malloc(sizeof(Node));
    strcpy(newNode->song, song);
    newNode->next = newNode; 
    return newNode;
}


Node* insertEnd(Node *last, char *song) {
    Node *newNode = createNode(song);
    if (last == NULL) {
        return newNode;
    }
    newNode->next = last->next;
    last->next = newNode;
    return newNode; 
}


Node* deleteSong(Node *last, char *song, int *found) {
    if (last == NULL) {
        return NULL;
    }

    Node *curr = last->next, *prev = last;
    do {
        if (strcmp(curr->song, song) == 0) {
            *found = 1;
            if (curr == prev) {
                free(curr);
                return NULL; 
            }
            if (curr == last) {
                last = prev;
            }
            prev->next = curr->next;
            free(curr);
            return last;
        }
        prev = curr;
        curr = curr->next;
    } while (curr != last->next);

    return last; 
}


void displayPlaylist(Node *last) {
    if (last == NULL) {
        printf("Playlist is empty\n");
        return;
    }
    Node *curr = last->next;
    do {
        printf("%s ", curr->song);
        curr = curr->next;
    } while (curr != last->next);
    printf("\n");
}

int main() {
    int n;
    scanf("%d", &n);

    if (n < 1 || n > 100) {
        printf("Invalid input\n");
        return 0;
    }

    Node *last = NULL;
    char song[MAX_LEN];

    
    for (int i = 0; i < n; i++) {
        if (scanf("%s", song) != 1) {
            printf("Invalid input\n");
            return 0;
        }
        last = insertEnd(last, song);
    }

    char deleteSongName[MAX_LEN];
    if (scanf("%s", deleteSongName) != 1) {
        printf("Invalid input\n");
        return 0;
    }

    int found = 0;
    last = deleteSong(last, deleteSongName, &found);

    if (!found) {
        printf("Song not found\n");
    } else if (last == NULL) {
        printf("Playlist is empty\n");
    } else {
        displayPlaylist(last);
    }

return 0;
}