#include<iostream>
#include<string>
#include<cctype>
#include<algorithm>

using namespace std;

struct Node {
    string title;
    Node* next;
    Node() : title(), next(nullptr) {}
    Node(const string &t) : title(t), next(nullptr) {}
};

static string trim(const string &s) {
    int l = 0, r = (int)s.size() - 1;
    while (l <= r && isspace((unsigned char)s[l])) ++l;
    while (r >= l && isspace((unsigned char)s[r])) --r;
    if (l > r) return string();
    return s.substr(l, r - l + 1);
}

static bool isValidTitle(const string &s) {
    if (s.empty()) return false;
    for (unsigned char c : s) {
        if (!(isalpha(c) || c == ' ')) return false;
    }