int main() {
    int n;
    scanf("%d", &n);
    getchar(); 

    for (int i = 0; i < n; i++) {
        char visitorName[100];
        fgets(visitorName, sizeof(visitorName), stdin);
        visitorName[strcspn(visitorName, "\n")] = '\0'; 
        if (!isValidName(visitorName)) {
            printf("Invalid input\n");
            Node* current = head;
            while (current != NULL) {
                Node* temp = current;
                current = current->next;
                free(temp);
            }
            return 0; 
        }
        addVisitor(visitorName);
    }
    Node* current = head;
    while (current != NULL) {
        printf("%s", current->name);
        if (current->next != NULL) {
            printf(" "); 
        }
        current = current->next;
    }
    printf("\n");
    current = head;
    while (current != NULL) {
        Node* temp = current;
        current = current->next;
        free(temp);
    }

    return 0;
}