#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->next;
    temp->prev->next=NULL;
    free(temp);
    return head;
    
}
void println(node*head){
    node*temp=head;
    int first=1;
    while(temp1=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;
}
    
}