Bus Stop

View as PDF

Submit solution

Points: 5
Time limit: 2.0s
Memory limit: 62M

Author:
Problem type

jsumabat spent too much time at his school's Computer Club (every Thursday in Room 221) and he is about to be late for the bus. He needs your help to determine the minimum time necessary to get to the bus stop.

The area around the school and the bus stop can be divided into a grid of squares. jsumabat starts on one of these squares and can travel to any adjacent square or to a square directly diagonal to his square. Given the position of the school and the bus stop, as well as the travel time, determine the minimum amount of time to get to the bus stop from the school.

Input Specification

The first line contains c_a (1 \le c_a \le 1000) representing the cost in minutes to travel to any adjacent square.

The second line contains c_d (c_a \le c_d < 2c_a) representing the cost in minutes to travel diagonally.

The next line contains two space separated integers, representing the 0 indexed x_s (0 \le x_s < 10^6) and y_s (0 \le y_s < 10^6) coordinates of the school, with (0, 0) being the top left corner of the grid.

The final line contains two space separated integers, representing the 0 indexed x_f (0 \le x_f < 10^6) and y_f (0 \le y_f < 10^6) coordinates of the bus stop, the final destination.

Output Specification

Output the minimum number of minutes jsumabat needs to travel from the school to the bus stop.

Sample Input

2
3
0 0
4 4

Sample Output

12

Comments

There are no comments at the moment.