#include <stdio.h>
#include <stdlib.h>
#include<ctype.h>
#include <string.h>

typedef struct Node
{
   int data;
   struct node*next;
   struct node*prev;
}Node;
Node*createNode(int data)
{
Node*newNode=(Node*)malloc(sizeof(node));
if (!newNode){
   printf("memory allocation failed\n");
   exit(1);
   }
   newNode->data=data;
   newNode->next=NULL;
   newNode->prev=NULL;
   return newNode;
 }
 void append(Node**head,int data){
Node*newNode=createNode(data);
   if(*head==NULL){
   *head=newNode;
   return;
   }
   node*temp=*head;
   while(temp->next!=NULL)
     temp=temp->next;
   temp->next=newNode;
   newNode->prev=temp;
 }
 void printList(Node*head)
 {
     Node*temp=head;
     while(temp!=NULL);
     {
         printf("%d",temp->data);
         if(temp->next!=NULL)
          print(" ");
         temp=temp->next;
     }
     printf("\n");
 }
int isvalidinteger(char*str)
{
        if(*str=='-'||*str=='+')str++;
        if(*str=='\0')return 0;
        while (*str)
        {
            if(!isdigit(*str))
              return 0;
            str++;
        }
        return 1;
}
int main()
{
    int n;
    char buffer[100];
    if(!fgets(buffer,sizeof(buffer)),stdin)){
        printf("Invalid input\n");
        return 0;
    }
    buffer[strcspn(buffer,"\n")]=0;
    if(!isvalidinteger(buffer)){
        printf("Invalid input");
        return 0;
    }
    n=atoi(buffer);
    if(n<=0){
        printf("Invalid input\n");
        return 0;
    }
    Node*head=NULL;
    for(int i=0;i<n;i++){
        if(!isvalidinteger(buffer)){
            printf("Invalid input\n");
            return 0;
        }
        int id=atoi(buffer);
        append(&head,id);
    }
    printList(head);
    Node*temp;
    while(head!=NULL){
        temp=head;
        head=head->next;
        free(temp);
    }
    return 0;
}