# problem

Complete a program that calculates how many floors the elevator has traveled. However, the elevator must initially be on the ground floor.

# Example

From the 1st floor to the 3rd floor → 2nd floor has been moved, so a total of 2nd floor From the 3rd floor to the 1st floor → 2 floors have been moved, so a total of 4 floors From the 1st floor to the 4th floor → 3 floors have been moved, so a total of 7 floors

# Value to be entered

The input is given in the following format.

N f_1 ... f_N -The first line is given an integer N that indicates the number of lines in the log. ・ In the following N lines, the floor f_i (1 ≤ i ≤ N) where the elevator stopped is entered in order as an integer. • The total input is N + 1 lines, with one line break at the end of the last line.

# Expected output

Please output the number of floors the elevator has moved as an integer.

3 3 1 4

7

# My answer (I referred to the volunteer site)

#### `python`

``````
n = gets.to_i
i = 1
s = 0
n.times {
a = gets.to_i
s += (a - i).abs
i = a
}
puts s
``````