#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>

typedef struct Node {
    char task[101];
    struct Node *prev, *next;
} Node;

int containsDigit(char *str) {
    while (*str) {
        if (isdigit(*str)) return 1;
        str++;
    }
    return 0;
}

Node* createNode(char *taskName) {
    Node newNode = (Node)malloc(sizeof(Node));
    strcpy(newNode->task, taskName);
    newNode->prev = newNode->next = NULL;
    return newNode;
}

void printList(Node *head) {
    while (head) {
        printf("%s", head->task);
        if (head->next) printf(" ");
        head = head->next;
    }
    printf("\n");
}

int main() {
    int n;
    scanf("%d", &n);

    Node *head = NULL, *tail = NULL;

    for (int i = 0; i < n; i++) {
        char temp[101];
        scanf("%s", temp);
        Node *newNode = createNode(temp);
        if (!head) {
            head = tail = newNode;
        } else {
            tail->next = newNode;
            newNode->prev = tail;
            tail = newNode;
        }
    }

    char newTask[101];
    scanf("%s", newTask);

    if (containsDigit(newTask)) {
        printf("Invalid input\n");
        return 0;
    }

    Node *newNode = createNode(newTask);
    newNode->next = head;
    if (head) head->prev = newNode;
    head = newNode;

    printList(head);
    return 0;
}