#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define MAX_SONGS 100
#define MAX_LEN 100

typedef struct Node {
    char name[MAX_LEN];
    struct Node* next;
} Node;

// Function to create a new node
Node* createNode(char* name) {
    Node* newNode = (Node*)malloc(sizeof(Node));
    strcpy(newNode->name, name);
    newNode->next = NULL;
    return newNode;
}

// Function to delete a song from circular list
Node* deleteSong(Node* head, char* target, int* found) {
    if (!head) return NULL;

    Node *curr = head, *prev = NULL;
    do {
        if (strcmp(curr->name, target) == 0) {
            *found = 1;
            if (curr == head && curr->next == head) {
                free(curr);
                return NULL;
            }
            if (curr == head) {
                // Find last node to update its next
                Node* last = head;
                while (last->next != head) last = last->next;
                head = head->next;
                last->next = head;
                free(curr);
                return head;
            } else {
                prev->next = curr->next;
                free(curr);
                return head;
            }
        }
        prev = curr;
        curr = curr->next;
    } while (curr != head);

    return head;
}

int main() {
    int n;
    scanf("%d", &n);

    if (n < 1 || n > MAX_SONGS) {
        printf("Invalid input\n");
        return 0;
    }

    Node *head = NULL, *tail = NULL;
    char song[MAX_LEN];
    for (int i = 0; i < n; i++) {
        if (scanf("%s", song) != 1) {
            printf("Invalid input\n");
            return 0;
        }
        Node* newNode = createNode(song);
        if (!head) {