#K76692. Sum of Adjacent Differences

    ID: 34699 Type: Default 1000ms 256MiB

Sum of Adjacent Differences

Sum of Adjacent Differences

Given a list of integers, your task is to compute the sum of the absolute differences between each pair of adjacent elements. Formally, for a list \(a_1, a_2, \dots, a_n\), you need to calculate:

\[ S = \sum_{i=1}^{n-1} |a_i - a_{i+1}|, \]

If the list contains fewer than two elements, the sum is defined to be 0.

This problem tests your ability to process input and perform basic arithmetic operations.

inputFormat

The input is provided via standard input (stdin) in the following format:

  • The first line contains a single integer \(n\) which indicates the number of elements in the list.
  • The second line contains \(n\) space-separated integers representing the list elements.

outputFormat

Output a single integer — the sum of absolute differences between consecutive elements of the list. If the list contains fewer than two elements, output 0.

## sample
0
0

</p>