Elevator
Limits: 2 sec., 256 MiB
This statement was translated automatically from Ukrainian.
***
Fifteen-story ones are made of brick, nine-story ones are made of concrete -
Identical buildings across and along my neighborhood.
***
So once said a Lviv artist from a neighborhood on the outskirts of the city. Today, his follower is researching the elevators in these buildings. He climbs to a certain floor on foot, and then rides back and forth between floors until the elevator breaks down or he gets tired. You need to find the total duration of the trip.
Input
The first line contains a single number \(n\) — the number of visited floors, as well as the number \(t\) — how many seconds the elevator ride takes from one floor to the adjacent one. The elevator moves at a constant speed, so, for example, a trip from the first to the fourth floor will take \(3 \cdot t\) seconds.
The second line contains \(n\) space-separated numbers — the numbers of the floors that were visited (in order).
Output
Print a single number — the total travel time in seconds.
Constraints
\(2 \leq n \leq 100\),
\(1 \leq t \leq 10\),
the number of each floor is an integer from 1 to 16.
Samples
| Input (stdin) | Output (stdout) |
|---|---|
| 3 2 1 4 3 | 8 |
| Input (stdin) | Output (stdout) |
|---|---|
| 2 10 16 5 | 110 |
Notes
In the first example, the trip from the 1st to the 4th floor takes 6 seconds, and then the trip to the 3rd takes another 2 seconds. Total 8.
Submit a solution
| Element Type | Created | Who | Problem | Compiler | Result | Time (sec.) | Memory (MiB) | # | Actions |
|---|
| Element Type | Created | Who | Problem | Compiler | Result | Time (sec.) | Memory (MiB) | # | Actions |
|---|