#include <stdio.h>
#include <stdlib.h>
struct Node{
    int data;
    struct Node *prev,*next;
};
struct Node *createNode(int val){
    struct Node* newNode=(struct Node*) malloc (sizeof(struct Node));
    newNode->data=val;
    newNode->prev=newNode->next=NULL;
    return newNode;
}
void printList(struct Node* head){
    struct Node* temp=head;
    while(temp){
        printf("%d ",temp->data);
        temp=temp->next;
    }
    printf("\n");
}
struct Node* deleteLast(struct Node* head)
struct Node* temp;{
    if(!head || !head->next)return NULL;
    free(temp);
    return head;
}
int main(){
    int n,val;
    scanf("%d",&n);
    if(n<0){
        printf("Invalid input");
        return 0;
    }
    struct Node *head=NULL,*tail=NULL;
    for(int i=0;i<n;i++){
        scanf("%d",&val);
        struct Node*newNode=createNode(val);
        if(!head)head=tail=newNode;
        else{
            tail->next=newNode;
            newNode->prev=tail;
            tail=newNode;
        }
    }
    printList(head);
    head=deleteLast(head);
    if(head) printList(head);
    return 0;
}