#include <bits/stdc++.h>
#include <cmath> 
using namespace std;


struct Node {
    int data;
    Node* next;

    
};


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

    int sum = 0;
    Node* current = root;

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

    return sum;
}


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

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


void print(Node* root) {
    Node* current = root;
    while (current) {
        cout << current->data << " ";
        current = current->next;
    }
    cout << endl;
}


int main() {
    Node* root= NULL;

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

    
    std::cout << "Linked list: ";
    print(root);

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

    return 0;
}
