#include<stdio.h>
#include<stdlib.h>
struct node{
    int data;
    struct node* next;
    struct node* prev;
};
int main(){
    int n;
    scanf("%d",&n);
    if(n<0){
        printf("Invalid input");
        return 0;
    }
    struct node* head=NULL;
    struct node* temp=NULL;
    struct node* current;
    for(int i=0;i<n;i++){
        int value,num;
        scanf("%d",&value);
        struct node* newnode=(struct node*)malloc(sizeof(struct node));
        newnode->data=value;
        newnode->next=NULL;
        newnode->prev=NULL;
        
        if(head==NULL){
            head=newnode;
        }
        else{
            temp=head;
            while(temp->next!=NULL){
                temp=temp->next;
            }
            temp->next=newnode;
            newnode->prev=temp;
            temp=newnode;}
            temp->next=head;
            head->prev=temp;
            current=head;
        do{
            temp=temp->next;
            printf("%d",temp->data);
          
            while(current!=NULL){
                 printf(" ");
            }    
        } 
        return 0;
    }
}