// editor2
#include<stdio.h>
#include<stdlib.h>
struct node{
    int data;
    struct node*prev,*next;
};
struct node*createnode(int data)
{
    struct node*newnode=(struct node*)malloc(sizeof(struct node));
    newnode->data=data;
    newnode->prev=newnode->next=NULL;
    return newnode;
}
void printlist(struct node*head)
{
    struct node*temp=head;
    while(temp!=NULL)
    {
        printf("%d",temp->data);
        if(temp->next!=NULL)
        printf(" ");
        temp=temp->next;
    }
    printf("\n");
    
    }
    void deletelast(struct node**head)
    {
        if(*head==NULL)
        return;
        struct node*temp=*head;
        while(temp->next!=NULL)
        {
            temp=temp->next;
        }
        
    }
    if(temp->prev==NULL)
    {
        *head=NULL;
    }
    else{
        temp->prev->next=NULL;
        
    }
    free(temp);
    }
    }
    int main()
    {
        int n;
        scanf("%d",&n);
        printf("Invalid input\n");
        return 0;
    }
    if(n==0)
    {
        printf("\n\n");
        return 0;
    }
    struct node*head=NULL,*tail=NULL;
    for(int i=0;i<n;i++)
    {
        int val;
        scanf("%d",&val);
        struct node*newnode=createnode(val);
        if(head==NULL)
        {
            head=tail=newnode;
        }
        else{
            tail->next=newnode;
            newnode->pre=tail;
            tail=newnode;
        }
    }
    printlist(head);
    deletelast(&head);
    printlist(head);
    return 0;
    }
}