#include<stdio.h>
#include<stdlib.h>

typedef struct Node{
    int data;
    struct Node *next;
    struct Node *prev;
}node;

node *head=NULL,*tail,*prev,*temp;

void create(int num){
    node *newNode = (node*)malloc(sizeof(node));
    newNode->data = num;
    newNode->next = NULL;
    if(head==NULL){
        head = newNode;
        head->prev = NULL;
    }
    else {
        newNode->prev = tail;
        tail->next = newNode;
    }
    tail = newNode;
}

void display(){
    node *i;
    for(i=tail;i!=NULL;i=i->prev){
        printf("%d ",i->data);
    }
}

void Del(int del){
    node *i;
    int cnt=0;
    for(i=head;i!=NULL;i=i->next){
        if(i->data == del){
            i->prev->next = i->next;
            cnt++;
        }
        else{
            printf("%d ",i->data);
        }
    }
    // if(!cnt){
    //     printf("Node not found");
    //     exit(0);
    // }
}

int main(){
    int n,num,del;
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        scanf("%d",&num);
        create(num);
    }
    scanf("%d",&del);
    // Del(del);
    display():

}