#include <iostream>
#include <string>
#include <cctype>

// Node structure for the singly linked list
struct Node {
    std::string data;
    Node* next;
};

// Function to check if a string contains only alphanumeric characters
bool isAlphanumeric(const std::string& str) {
    for (char const &c : str) {
        if (!isalnum(c)) {
            return false; // Found a non-alphanumeric character
        }
    }
    return true; // All characters are alphanumeric
}

// Function to free the memory used by the linked list to prevent memory leaks
void freeList(Node* head) {
    while (head != nullptr) {
        Node* temp = head;
        head = head->next;
        delete temp;
    }
}

int main() {
    // Use fast I/O
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(NULL);

    int n;
    std::cin >> n;

    Node* head = nullptr;
    Node* tail = nullptr; // Pointer to the last node for efficient appends
    bool hasInvalidInput = false;

    // 1. Read all n names and build the linked list first.
    // This ensures we have the full list before validating.
    for (int i = 0; i < n; ++i) {
        std::string name;
        std::cin >> name;
        
        // Create a new node and add it to the end (tail) of the list
        Node* newNode = new Node{name, nullptr};
        if (head == nullptr) {
            // If the list is empty, the new node is both the head and the tail
            head = newNode;
            tail = newNode;
        } else {
            // Append the new node after the current tail and update the tail
            tail->next = newNode;
            tail = newNode;
        }
    }

    // 2. Now, traverse the complete list to validate all names.
    Node* current = head;
    while (current != nullptr) {
        if (!isAlphanumeric(current->data)) {
            hasInvalidInput = true;
            break; // An invalid name was found, no need to check further
        }
        current = current->next;
    }

    // 3. Print the output based on the validation result.
    if (hasInvalidInput) {
        std::cout << "Invalid input\n";
    } else {
        // If all names are valid, print them from the list
        current = head;
        while (current != nullptr) {
            std::cout << current->data;
            // Add a space only if it's not the last name
            if (current->next != nullptr) {
                std::cout << " ";
            }
            current = current->next;
        }
        std::cout << "\n";
    }

    // 4. Clean up the dynamically allocated memory
    freeList(head);

    return 0;
}