#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<ctype.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;
}
int isNumeric(char *str)
{
    int i=0;
    if(str[0]== '-') i=1;
    for(; str[i];i++)  
    {
        if(!isdigit(str[i]))
        return 0;
    }
    return 1;
}
void printList(struct node*head)
{
    struct node*temp= head;
    while(temp!=NULL)
    {
        printf("%d",temp->data);
        if(temp->next)
        printf(" ");
        temp=temp->next;
    }
    printf("\n"); 
}
int main()
{
    int n;
    scanf("%d",&n);
    if(n==0)
    {
        printf("Value not found\n");
        return 0;
    }
    struct node*head=NULL;
    struct node*tail=NULL;
    char input[50];
    for(int i=0;i<n;i++)
    {
        scanf("%s",input);
        if(!isNumeric(input))
        {
            printf("Invalid input\n");
            return0;
        }
        int value=atoi(input);
        struct node*newnode=createnode(value);
        if(head==NULL)
          head= tail=newnode;
        else
        {
            tail->next=newnode;
            tail=newnode;
        }
    }
    int oldVal,newVal;
    scanf("%s",input);
    if(!isNumeric(input))
    {
        printf("Invaid input\n");
        return 0;
    }
    oldVal=atoi(input);
    scanf("%s",input);
    if(!isNumeric(input))
    {
        printf("Invalid input\n");
        return 0;
    }
    newVal=atoi(input);
    struct node*temp=head;
    int found=0;
    while(temp!=NULL)
    {
        if(temp->data==oldVal)
        {
            temp->data=newVal;
            found = 1;
        }
        temp=temp->next;
    }
    if(found)
    {
        printf("Value not found\n");
    }
    else
    {
        printList(head);
    }
    return 0;
}