atcoder#ARC109A. [ARC109A] Hands

[ARC109A] Hands

Score : 300300 points

Problem Statement

There are two 100100-story buildings, called A and B. (In this problem, the ground floor is called the first floor.)

For each i=1,,100i = 1,\dots, 100, the ii-th floor of A and that of B are connected by a corridor. Also, for each i=1,,99i = 1,\dots, 99, there is a corridor that connects the (i+1)(i+1)-th floor of A and the ii-th floor of B. You can traverse each of those corridors in both directions, and it takes you xx minutes to get to the other end.

Additionally, both of the buildings have staircases. For each i=1,,99i = 1,\dots, 99, a staircase connects the ii-th and (i+1)(i+1)-th floors of a building, and you need yy minutes to get to an adjacent floor by taking the stairs.

Find the minimum time needed to reach the bb-th floor of B from the aa-th floor of A.

Constraints

  • 1a,b,x,y1001 \leq a,b,x,y \leq 100
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

aa bb xx yy

Output

Print the minimum time needed to reach the bb-th floor of B from the aa-th floor of A.

2 1 1 5
1

There is a corridor that directly connects the 22-nd floor of A and the 11-st floor of B, so you can travel between them in 11 minute. This is the fastest way to get there, since taking the stairs just once costs you 55 minutes.

1 2 100 1
101

For example, if you take the stairs to get to the 22-nd floor of A and then use the corridor to reach the 22-nd floor of B, you can get there in 1+100=1011+100=101 minutes.

1 100 1 100
199

Using just corridors to travel is the fastest way to get there.