# Task

John is a programmer. He treasures his time very much. He lives on the `n` floor of a building. Every morning he will go downstairs as quickly as possible to begin his great work today.

There are two ways he goes downstairs: walking or taking the elevator.

When John uses the elevator, he will go through the following steps:
```
1. Waiting the elevator from m floor to n floor;
2. Waiting the elevator open the door and go in;
3. Waiting the elevator close the door;
4. Waiting the elevator down to 1 floor;
5. Waiting the elevator open the door and go out;
(the time of go in/go out the elevator will be ignored)
```

Given the following arguments:
```
n: An integer. The floor of John(1-based).
m: An integer. The floor of the elevator(1-based).
speeds: An array of integer. It contains four integer [a,b,c,d]
        a: The seconds required when the elevator rises or falls 1 floor
        b: The seconds required when the elevator open the door
        c: The seconds required when the elevator close the door
        d: The seconds required when John walks to n-1 floor
```

Please help John to calculate the shortest time to go downstairs.




# Example

For `n = 5, m = 6 and speeds = [1,2,3,10]`, the output should be `12`.

John go downstairs by using the elevator:

`1 + 2 + 3 + 4 + 2 = 12`

For `n = 1, m = 6 and speeds = [1,2,3,10]`, the output should be `0`.

John is already at 1 floor, so the output is `0`.

For `n = 5, m = 4 and speeds = [2,3,4,5]`, the output should be `20`.

John go downstairs by walking:

`5 x 4 = 20`

Difficulty: EASY
Starter code: def shortest_time(n, m, speeds):
	

Solutions:
def shortest_time(n, m, speeds):
	(lift, open, close, walk) = speeds
	return min(abs(m - n) * lift + open + close + (n - 1) * lift + open, (n - 1) * walk)


def shortest_time(n, m, speeds):
	(a, b, c, d) = speeds
	elevator = (abs(m - n) + n - 1) * a + b * 2 + c
	walk = (n - 1) * d
	return min(elevator, walk)


def shortest_time(n, m, speeds):
	(elevator_speed, open_door, close_door, walk_speed) = speeds
	elevator_time = (abs(m - n) + n - 1) * elevator_speed + open_door * 2 + close_door
	walk_time = (n - 1) * walk_speed
	return min(elevator_time, walk_time)


def shortest_time(n, m, speeds):
	(move_lift, open_door, close_door, move_feet) = speeds
	healthy = (n - 1) * move_feet
	lazy = abs(n - m) * move_lift + open_door + close_door + (n - 1) * move_lift + open_door
	return min(healthy, lazy)


def shortest_time(n, m, speeds):
	return min([speeds[3] * (n - 1), (abs(m - n) + n - 1) * speeds[0] + 2 * speeds[1] + speeds[2]])


def shortest_time(n, m, speeds):
	b = (n - 1 + max(m, n) - min(m, n)) * speeds[0] + speeds[2] + speeds[1] * 2
	a = speeds[-1] * (n - 1)
	return b if a > b else a


def shortest_time(n, m, speeds):
	if n == 1:
		return 0
	else:
		(move, open, close, walk) = speeds
		elevator = abs(n - m) * move + open + close + move * (n - 1) + open
		walking = walk * (n - 1)
	return min(elevator, walking)