// editor5
#include <stdio.h>
#include <stdlib.h>
struct node
{
    int data;
    struct node*next;
}*head=NULL,*tail;
int main()
{
    int n,i;
    scanf("%d",&n);
    for(i=0;i<n;i++)
    {
        struct node* newnode=(struct node*)malloc(sizeof(struct node));
        if(scanf("%d",&newnode->data)!=1)
        {
            printf("Invalid input");
            return 0;
        }
        if(head==NULL)
        {
            head=newnode;
            tail=newnode;
            head->next=NULL;
        }else
        {
            tail->next=newnode;
            tail=newnode;
            newnode->next=NULL;
        }
    } 
    int o,v,flag=0;
    scanf("%d %d",&o,&v);
    struct node* temp=head;
    while(temp)
    {
        if(temp->data==o)
        {
        temp->data=v;
        flag=1;
        }
    }
    if(flag==0)
    printf("Value not found");
    else
    while(head)
{
printf("%d ",head->data);
head=head->next;
}
}