I found an interesting problem on https://codeforces.com/problemset/problem/746/C:
The tram in Berland goes along a straight line from the point 0 to the point s and back, passing 1 meter per t_1 seconds in both directions. It means that the tram is always in the state of uniform rectilinear motion, instantly turning around at points x = 0 and x = s.

Igor is at the point x_1. He should reach the point x_2. Igor passes 1 meter per t_2 seconds. 

Your task is to determine the minimum time Igor needs to get from the point x_1 to the point x_2, if it is known where the tram is and in what direction it goes at the moment Igor comes to the point x_1.

Igor can enter the tram unlimited number of times at any moment when his and the tram's positions coincide. It is not obligatory that points in which Igor enter and exit the tram are integers. Assume that any boarding and unboarding happens instantly. Igor can move arbitrary along the line (but not faster than 1 meter per t_2 seconds). He can also stand at some point for some time.


-----Input-----

The first line contains three integers s, x_1 and x_2 (2 ≤ s ≤ 1000, 0 ≤ x_1, x_2 ≤ s, x_1 ≠ x_2) — the maximum coordinate of the point to which the tram goes, the point Igor is at, and the point he should come to.

The second line contains two integers t_1 and t_2 (1 ≤ t_1, t_2 ≤ 1000) — the time in seconds in which the tram passes 1 meter and the time in seconds in which Igor passes 1 meter.

The third line contains two integers p and d (1 ≤ p ≤ s - 1, d is either 1 or $- 1$) — the position of the tram in the moment Igor came to the point x_1 and the direction of the tram at this moment. If $d = - 1$, the tram goes in the direction from the point s to the point 0. If d = 1, the tram goes in the direction from the point 0 to the point s.


-----Output-----

Print the minimum time in seconds which Igor needs to get from the point x_1 to the point x_2.


-----Examples-----
Input
4 2 4
3 4
1 1

Output
8

Input
5 4 0
1 2
3 1

Output
7



-----Note-----

In the first example it is profitable for Igor to go by foot and not to wait the tram. Thus, he has to...

I tried it in Python, but could not do it. Can you solve it?
s, x1, x2 = list(map(int, input().split()))
t1, t2 = list(map(int, input().split()))
p, d = list(map(int, input().split()))

if x2 < x1:
    x1, x2 = s - x1, s - x2
    d *= -1
    p = s - p


if t2 <= t1:
    print(t2 * abs(x1 - x2))
    return

if p <= x1 and d == 1:
    print(min(t2 * abs(x1 - x2), t1* abs(p - x2)))
elif d == 1:
    print(min(t2 * abs(x1 - x2), t1*s + t1*(s-p) + t1 * abs(x2)))
else:
    print(min(t2 * abs(x1 - x2), t1*(p) + t1 * abs(x2)))