#include<stdio.h>
#include<stdlib.h>
typedef struct node 
{
    int data;
    struct node *next;
    struct node *prev;
}
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);
        temp=temp->next;
    }
    printf("\n");
}
struct Node* deleteLast(struct Node*head) {
    if(head==NULL)
    return NULL;
    if(head->next==NULL) {
        free(head);
        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;
    scanf("%d", &n);
    if(n<0) {
        printf("Invalid input\n");
        return 0;
    }
    struct Node*head=NULL;
    struct Node*tail=NULL;
    for(int i=0;i<n;i++) {
        int val;
        scanf("%d", &val);
        struct Node*newNode=createNode(val);
        if(head==NULL) 
            head=tail=newNode;
        else {
            tail->next=newNode;
            newNode->prev=tail;
            tail=newNode;
        }
    }
    printList(head);
    head=deleteLast(head);
    printList=(head);
    return 0;
}