#include <stdio.h>
#include <stdlib.h>
// Define the structure for a doubly linked list node
typedef struct Node{
    int data;
    struct Node* next;
    struct Node* prev;
} Node;
// Function to create a new node
Node* createNode(int data){
    Node* newNode = (Node*)malloc(sizeof(Node));
    if (!newNode){
        printf("Memory error\n");
        return NULL;
    }
newNode->data = data;
newNode->next = NULL;
newNode->prev = NULL;
return newNode;
}
// Function to insert a bode at the end of the doubly linked list
void insertNode(Node** head, int data){
    if (*head == NULL){
        *head = newNode;
    } else {
    Node* temp = *head;
    while (temp->next){
        temp = temp->next;
    }
temp->next = newNode;
newNode->prev = temp;
   }
}
// Function to delete the last node from the doubly linked list
void deleteLastNode(Node** head){
    if (*head == NULL){
        return;
    } else {
        Node*temp = *head;
        while (temp->next){
            temp = temp->next;
        }
        temp->prev->next = NULL;
        free(temp);
    }
}
// Function to print the doubly linked list
void printList(Node* head){
    while(head){
        printf("%d ", head->data);
        head = head->next;
    }
    printf("\n");
}
int main(){
    int n;
    scanf("%d" , &n);
    if (n < 0){
        printf("Invalid Input\n");
        return 0;
    }
Node* head = NULL
for (int i = 0; i < n; i++) {
    int data;
    scanf("%d" , &data);
    insertNode(&head,data);
}
printList(head);
deleteLastNode(&head);
printList(head);
return 0;
}