#include <iostream>
#include <string>
#include <cctype>
using namespace std;

struct Node {
    string data;
    Node* prev;
    Node* next;
    Node(string val) {
        data = val;
        prev = next = NULL;
    }
};
void insertAtHead(Node*& head, string val) {
    Node* newNode = new Node(val);
    newNode->next = head;
    if (head != NULL) {
        head->prev = newNode;
    }
    head = newNode;
}


void printList(Node* head) {
    Node* temp = head;
    while (temp != NULL) {
        cout << temp->data;
        if (temp->next != NULL) cout << " ";
        temp = temp->next;
    }
    cout << endl;
}

bool hasDigits(string s) {
    for (char c : s) {
        if (isdigit(c)) return true;
    }
    return false;
}

int main() {
    int n;
    cin >> n;
    Node* head = NULL;
    Node* tail = NULL;

    
    for (int i = 0; i < n; i++) {
        string task;
        cin >> task;
        Node* newNode = new Node(task);
        if (head == NULL) {
            head = tail = newNode;
        } else {
            tail->next = newNode;
            newNode->prev = tail;
            tail = newNode;
        }
    }

    
    string newTask;
    cin >> newTask;

    
    if (hasDigits(newTask)) {
        cout << "Invalid input" << endl;
    } else {
        insertAtHead(head, newTask);
        printList(head);
    }

    return 0;
}