// editor3
#include <stdio.h>
#include <stdlib.h>
struct Node {
    int data;
    struct Node* next;
};
void replaceData(struct Node** head, int oldData, int newData) {
    struct Node* current = *head;

    while (current != NULL) {
        if (current->data == oldData) {
            current->data == newData;
        }
        current = current->next;
    }
}

int main() {
    int i, n, dl, newData;
    scanf("%d", &n);

    struct Node *p, *q, *head;

    q = malloc(sizeof(struct Node));
    if (q == NULL) {
        printf("Memory allocation failed\n");
        return 1;
    }
    scanf("%d", &q->data);
    q->next = NULL;
    head = q;
    p = head;
    if(1<=n<=1000)
    {
        printf("List is empty");
    }
    else(0<=k<=n)
    {
        printf("Invalid input");
    }
    for (i = ; i <= n; i++) {
        q = malloc(sizeof(struct Node));
        if (q == NULL) {
            printf("Memory allocation failed\n");
            return 1;
        }
        scanf("%d", &q->data);
        q->next = NULL;
        p->next = q;
        p = p->next;
    }
    scanf("%d %d", &dl, &newData);
    replaceData(&head, dl, newData);
    p = head;
    while (p != NULL) {
        printf("%d ", p->data);
        p = p->next;
    }
    return 0;
}