#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->prev = temp;
       return head;
}
Node* deleteLast(Node* head){
    if(head == NULL || head->next == NULL){
        free(head);
        return NULL;
    }
    Node* temp = head;
    while temp = head;
    temp = temp->next;
    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 maain(){
    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);
    printfList(head);
    return 0;
}