// editor3
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
struct Node
{
    char data[50];
    struct Node *next;
    struct Node *prev;
};
struct Node *create(char data[50])
{
    struct Node *newnode=(struct Node*)malloc(sizeof(struct Node));
    newnode->next=NULL;
    newnode->prev=NULL;
    strcpy(newnode->data,data);
    return newnode;
}
void insert(char data[50],struct Node **head)
{
    struct Node *newnode=create(data),*temp=*head;
    if(*head==NULL)
    {
        *head=newnode;
    }
    else
    {
        while(temp->next!=NULL)
        {
            temp=temp->next;
        }
        temp->next=newnode;
        newnode->prev=temp;
    }
}
void insertAtStart(char data[50],struct Node **head)
{
    struct Node*newnode=create(data);
    newnode->next=*head;
    *head->prev=newnode;
    *head=newnode;
}
void print(struct Node*temp)
{
    while(temp!=NULL)
    {
        printf("%s ",temp->data);
        temp=temp->next;
    }
}
int main()
{
    int n;
    scanf("%d",&n);
    struct Node *head;
    for(int i=0;i<n;i++)
    {
        char data[50];
        scanf("%s",data);
        for (int j=0;j<strlen(data);j++)
        {
            if(isdigit(data[i])==0)
            {
                printf("Invalid input");
                return 0;
            }
        }
        insert(data,&head);
    }
    char data[50];
    scanf("%s",data);
    for(int i=0;i<strlen(data);i++)
    {
        if(isdigit(data[i])==0)
        {
            printf("Invalid input");
            return 0;
        }
    }
    insertAtStart(data,&head);
    print(head);
}