#C6229. Taco - Total Tree Height

    ID: 49966 Type: Default 1000ms 256MiB

Taco - Total Tree Height

Taco - Total Tree Height

In this problem, you are given an integer N representing the number of buildings in a street, followed by N integers denoting the heights of these buildings in sequential order.

The task is to determine the total height of all trees planted between the buildings. The height of a tree planted between two adjacent buildings is defined as the absolute difference between their heights. Formally, if the building heights are \(h_1, h_2, \ldots , h_N\), then the total tree height is computed as:

\[ \text{Total Height} = \sum_{i=1}^{N-1} |h_{i+1} - h_i| \]

Your program should read the input from standard input (stdin) and output the result to standard output (stdout).

Examples:

  • Input: 5 followed by 3 5 4 7 2 → Output: 11
  • Input: 3 followed by 4 4 4 → Output: 0
  • Input: 6 followed by 1 10 1 10 1 10 → Output: 45

inputFormat

The first line of input contains an integer N — the number of buildings.

The second line contains N space-separated integers representing the heights of the buildings in order.

outputFormat

Output a single integer, the total height of all trees computed as the sum of absolute differences between consecutive building heights.

## sample
5
3 5 4 7 2
11

</p>