// editor5
#include <stdio.h>
#include <stdlib.h>

typedef struct Node {
    int data;
    struct Node *next;
} Node;

Node* createNode(int value) {
    Node* newNode = (Node*)malloc(sizeof(Node));
    if (!newNode)
    exit(1);
    
    newNode->data = value;
    newNode->next = NULL;
    return newNode;
}
int main() {
    int n, x, y, found = 0;

    scanf("%d", &n);
    if(n < 0 || n > 1000) {
        printf("Invalid input");
        return 0;
    }
    Node *head = NULL, *tail = NULL, *temp = NULL;
    for (int i = 0; i < n; i++) {
        int val;
        if (scanf("%d", &val) != 1) {
            printf("Invalid input");
            return 0;
        }
        Node* newNode = createNode(val);
        if (head == NULL)
            head = newNode;
        else
            tail->next = newNode;
        tail = newNode;
    }
    scanf("%d %d", &x, &y);
    if(&x,&y!==2){
        printf("Invalid input");
        return 0;
    }
    temp = head;
    while (temp != NULL) {
        if (temp->data == x) {
            temp->data = y;
            found = 1;
        }
        temp = temp->next;
    }
    if (found) {
        temp = head;
        while (temp != NULL) {
            if (temp->next == NULL)
                printf("%d", temp->data);
            else
                printf("%d ", temp->data);
            temp = temp->next;
        }
    } else {
        printf("Value not found");
    }
    return 0;
}