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