#include<stdio.h>
#include<stdlib.h>

struct Node{
    int data;
    struct Node* next;
};

struct Node* createNode(int data)
{
    struct Node* newNode=(struct Node*)malloc(sizeof(struct Node));
    newNode->data=data;
    newNode->next=NULL;
    return newNode;
}

struct Node* append(struct Node* head, int data)
{
    struct Node*newNode=createNode(data);
    if(!head) return newNode;
    struct Node* yemp=head;
    while(temp->next)
      temp=temp->next;
    temp->next=newNode;
    return head;
    
}

struct Node* removeFirstAndLast(struct Node* head, int x, int* found)
{
    struct Node *temp=head,*prev=NULL;
    struct Node *firstPrev=NULL,*firstNode=NULL;
    struct Node *lastPrev=NULL,*lastNode=NULL;
    while(temp)
    {
        if(temp->data==x)
        {
            if(!firstNode)
            {
                firstNode=temp;
                firstPrev=prev;
            }
            lastNode=temp;
            lastPrev=prev;
        }
        prev=temp;
        temp=temp->next;
    }
    if(!firstNode)
    {
        *found=0;
        return head;
    }
    *found=1;
    if(lastNode)
    {
        if(lastPrev)
        {
            lastPrev->next=lastNode->next;
            
        }
        else
          head=lastNode->next;
        free(lastNode);
        }
    
    return head;
    
}

void printList(struct Node* head)
{
    struct Node* temp=head;
    while(temp)
    {
        printf("%d ",temp->data);
        temp=temp->next;
    }
}

int main(){
    int n;
    scanf("%d ",&n);
    if(n<=0)
    {
        printf("Invalid input");
        return 0;
    }
    struct Node* head=NULL;
    for(int i=0;i<n;i++)
    {
        int val;
        scanf("%d",&val);
        head=append(head,val);
    }
int x;
scanf("%d",&x);
int found=0;
head=removeFirstAndLast(head,x,&found)
if(!found){
    printf("Elemnt not found");
    return 0;
}    
printf("1\n");
printList(head);
return 0;
}