#K70642. Balance Score

    ID: 33354 Type: Default 1000ms 256MiB

Balance Score

Balance Score

You are given a list of n integers. Your task is to compute the balance score of the list, which is defined as the sum of the absolute differences between each consecutive pair of elements. Formally, for a list a0, a1, …, an-1, the balance score is given by:

[ \text{Balance Score} = \sum_{i=1}^{n-1} |a_i - a_{i-1}| ]

For example, if the list is [1, 3, 6, 10, 15], the balance score is calculated as:

[ |3-1| + |6-3| + |10-6| + |15-10| = 2 + 3 + 4 + 5 = 14 ]

If the list contains one or fewer elements, the balance score is defined to be 0.

inputFormat

The input is given via standard input and consists of two lines:

  • The first line contains an integer n denoting the number of elements in the list.
  • The second line contains n space-separated integers.

outputFormat

Output a single integer representing the balance score of the list. The output should be written to standard output.

## sample
5
1 3 6 10 15
14

</p>