#include <iostream>
#include <cmath>


struct Node {
    int data;
    Node* next;

    Node(int value) : data(value), next(nullptr) {}
};


int sumOfAbsoluteDifferences(Node* head) {
    if (!head || !head->next) {
        
        return 0;
    }

    int sum = 0;
    Node* current = head;

    
    while (current && current->next) {
        sum += std::abs(current->data - current->next->data);
        current = current->next->next;
    }

    return sum;
}


void appendNode(Node*& head, int value) {
    if (!head) {
        head = new Node(value);
        return;
    }

    Node* current = head;
    while (current->next) {
        current = current->next;
    }
    current->next = new Node(value);
}


void printList(Node* head) {
    Node* current = head;
    while (current) {
        std::cout << current->data << " ";
        current = current->next;
    }
    std::cout << std::endl;
}


int main() {
    Node* head = nullptr;

    
    appendNode(head, 10);
    appendNode(head, 20);
    appendNode(head, 15);
    appendNode(head, 5);

   
    std::cout << "Linked list: ";
    printList(head);

   
    int result = sumOfAbsoluteDifferences(head);
    std::cout << "Sum of absolute differences: " << result << std::endl;

    return 0;
}
