V#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, oldVal, newVal, found = 0;

    if (scanf("%d", &n) != 1 || 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;
    }

    if (scanf("%d %d", &oldVal, &newVal) != 2) {
        printf("Invalid input");
        return 0;
    }

    temp = head;
    while (temp != NULL) {
        if (temp->data == oldVal) {
            temp->data = newVal;
            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;
}