#include<stdio.h>
#include<string.h>
#include<stdlib.h>

typedef struct node{
    int data;
    struct node *next;
    struct node *prev;
    
}Node;

Node *head=NULL,*tail;

void create(int num){
    Node *newNode =(Node*)malloc(1*sizeof(Node));
    newNode->data=num;
    newNode->next=NULL;
    if(head==NULL){
        head=newNode;
        tail=newNode;
    }else{
        newNode->prev=tail;
        tail->next=newNode;
        tail=newNode;
    }
    head->prev=tail;
    tail->next=head;
}
void display(){
    Node *itr;
    for(itr=head;itr!=NULL;itr=itr->next){
        printf("%d ",itr->data);
    }
    printf("\n");
}

void del(){
    tail->prev->next=NULL;
    tail->next->prev=NULL;
    tail->next=head;

}

int main(){
    int n,num,i;
    scanf("%d",&n);
    if(n<0){
        printf("Invalid input");
        return 0;
    }
    for(i=0;i<n;i++){
        scanf("%d",&num);
        create(num);
    }
    display();
    del();
    display();
    return 0;
}