#C6229. Taco - Total Tree Height
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 by3 5 4 7 2
→ Output:11
- Input:
3
followed by4 4 4
→ Output:0
- Input:
6
followed by1 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.
## sample5
3 5 4 7 2
11
</p>