#include <stdio.h>
#include <stdlib.h>

struct node {
    int data;
    struct node* next;
};

struct node* head = NULL;
struct node* tail = NULL;

// Function to add node at the end
void append(int value) {
    struct node* newNode = (struct node*)malloc(sizeof(struct node));
    newNode->data = value;
    newNode->next = NULL;
    if (head == NULL) {
        head = tail = newNode;
    } else {
        tail->next = newNode;
        tail = newNode;
    }
}

int main() {
    int n, o, v;
    printf("Enter the number of elements in the linked list: ");
    scanf("%d", &n);

    printf("Enter %d elements:\n", n);
    for (int i = 0; i < n; i++) {
        int val;
        scanf("%d", &val);
        append(val);
    }

    printf("Enter old value and new value: ");
    scanf("%d%d", &o, &v);

    struct node* temp = head;
    int found = 0;
    while (temp != NULL) {
        if (temp->data == o) {
            temp->data = v;
            found = 1;
        }
        temp = temp->next;
    }