#C3209. Elevator Energy Calculation

    ID: 46611 Type: Default 1000ms 256MiB

Elevator Energy Calculation

Elevator Energy Calculation

Given a sequence of elevator stops, calculate the minimum energy required for the elevator to travel through all stops. The energy is defined as the total number of floors traversed between consecutive stops.

Formally, if the stops are given as \( f_1, f_2, \dots, f_n \), then the energy \( E \) is calculated as:

\( E = \sum_{i=2}^{n} |f_i - f_{i-1}| \)

If there is only one stop (i.e. \( n = 1 \)), the energy required is 0.

inputFormat

The first line of the input contains an integer \( n \) representing the number of elevator stops. The second line contains \( n \) space-separated positive integers representing the floor numbers where the elevator stops.

outputFormat

Output a single integer representing the minimum energy required for the elevator to make all the stops.

## sample
1
1
0