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