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 pass 2 meters and it takes 8 seconds in total, because he passes 1 meter per 4 seconds. 

In the second example Igor can, for example, go towards the point x_2 and get to the point 1 in 6 seconds (because he has to pass 3 meters, but he passes 1 meters per 2 seconds). At that moment the tram will be at the point 1, so Igor can enter the tram and pass 1 meter in 1 second. Thus, Igor will reach the point x_2 in 7 seconds in total.

Difficulty: interview

Starter code:

Solutions:
#!/usr/bin/env python3

def main():
    try:
        while True:
            s, x1, x2 = list(map(int, input().split()))
            t1, t2 = list(map(int, input().split()))
            p, d = list(map(int, input().split()))

            def travel(src, trg):
                nonlocal d
                if src == trg:
                    return 0
                if src < trg:
                    if d > 0:
                        return trg - src
                    else:
                        d = 1
                        return trg + src
                else:
                    if d < 0:
                        return src - trg
                    else:
                        d = -1
                        return s - src + s - trg

            a = travel(p, x1)
            b = travel(x1, x2)
            print("%d" % min(abs(x1 - x2) * t2, (a + b) * t1))

    except EOFError:
        pass

main()


s, x1, x2 = map(int, input().split())
t1, t2 = map(int, input().split())
p, d = map(int, input().split())
ans = abs(x1 - x2) * t2
if (x2 > x1):
    d *= -1
    p = s - p
    x1 = s - x1
    x2 = s - x2
    
if (d == -1):
    if (p < x1):
        ans = min(ans, (p + s + s - x2) * t1)
    else:
        ans = min(ans, (p - x2) * t1)
else:
    ans = min(ans, (s - p + s - x2) * t1)

print(ans)

s, start, finish = map(int, input().split())
tramsp, igorsp = map(int, input().split())
p, d = map(int, input().split())

if start == finish:
    print('0')
else:
    if p <= start and d == 1:
        t = (start - p) * tramsp
        nd = d
    elif p >= start and d == -1:
        t = (p - start) * tramsp
        nd = d
    elif p > start and d == 1:
        t = (2 * (s - p) + (p - start)) * tramsp
        nd = -1
    else:
        t = (2 * p + (start - p)) * tramsp
        nd = 1

    if start <= finish and nd == 1:
        t += (finish - start) * tramsp
    elif start >= finish and nd == -1:
        t += (start - finish) * tramsp
    elif start > finish and nd == 1:
        t += (2 * (s - start) + (start - finish)) * tramsp
    else:
        t += (2 * start + (finish - start)) * tramsp

    i = abs(start - finish) * igorsp

    print(min(t, i))

s, x1, x2 = map(int, input().split())
t1, t2 = map(int, input().split())
p, d = map(int, input().split())
ans = abs(x1 - x2) * t2
if x1 == x2:
    print(0)
elif x1 < x2:
    if (d == 1 and p <= x1) or p == 0:
        ans = min(ans, abs(x2 - p) * t1)
    elif d == -1 or p == s:
        ans = min(ans, (p + x2) * t1)
    elif d == 1 and p > x1:
        ans = min(ans, (s - p + s + x2) * t1)
else:
    if (d == -1 and p >= x1) or p == s:
        ans = min(ans, abs(p - x2) * t1)
    elif d == 1 or p == 0:
        ans = min(ans, (s - p + s - x2) * t1)
    elif d == -1 and p < x1:
        ans = min(ans, (p + s + s - x2) * t1)
print(ans)

from collections import defaultdict
import sys, os, math

def __starting_point():
    #n, m = list(map(int, input().split()))
    s, x1, x2 = list(map(int, input().split()))
    t1, t2 = list(map(int, input().split()))
    p, d = list(map(int, input().split()))
    if t1 >= t2:
        print(abs(x2 - x1) * t2)
        return
    
    if x2 > x1:
        #+dir
        if d == 1:
            if p <= x1:
                t = t1 * (x2 - p)
            else:
                t = t1 * (s + s - p + x2)
        else:
            t = t1 * (p + x2)
    else:
        if d == -1:
            if p >= x1:
                t = t1 * (p - x2)
            else:
                t = t1 * (s + s - x2 + p)
        else:
            t = t1 * (s - p + s - x2)
    print(min(t, abs(x2 - x1) * t2))
__starting_point()

s, x1, x2 = list(map(int, input().split()))
t1, t2 = list(map(int, input().split()))
p, d = list(map(int, input().split()))
if x1 > x2:
    x1 = s - x1
    x2 = s - x2
    d *= -1
    p = s - p
def dist(sx, fx, d, s):
    if d == -1:
        return sx + fx
    else:
        if fx >= sx:
            return fx - sx
        else:
            return 2 * s - abs(fx - sx)
if t1 > t2:
    print(t2 * (x2 - x1))
else:
    print(min(dist(p, x1, d, s) * t1 + (x2 - x1) * t1, (x2 - x1) * t2))


from sys import stdin

s,x1,x2=list(map(int,stdin.readline().split()))
t1,t2=list(map(int,stdin.readline().split()))
p,d=list(map(int,stdin.readline().split()))
#d=v*t t=d/v
if x1>=x2:
    x2,x1=s-x2,s-x1
    p=s-p
    d*=-1
tempsPied=(x2-x1)*t2

if d==-1:
    tempsTram=(p+x2)*t1
elif d==1 and p>x1:
    tempsTram=((s-p)+s+x2)*t1
else:
    tempsTram=(x2-p)*t1
print(min(tempsPied,tempsTram))


from math import *
s,x1,x2 =map(int,input().split())
t1,t2 = map(int,input().split())
p,d=map(int,input().split())
ans = abs(x1-x2)*t2
if t1 >= t2:
    print(ans)

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

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)))


#!/usr/bin/env python3

def ri():
    return list(map(int, input().split()))

s, x1, x2 = ri()
t1, t2 = ri()
p, d = ri()

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

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

print(m)


s,x1,x2=[int(i) for i in input().split()]
t1,t2=[int(i) for i in input().split()]
p,d=[int(i) for i in input().split()]
ans=abs(x1-x2)*t2
if d==-1:
    x1,x2=s-x1,s-x2
    p=s-p
x1t=[(x1-p)*t1,(2*s-x1-p)*t1,(2*s+x1-p)*t1]
x2t=[(x2-p)*t1,(2*s-x2-p)*t1,(2*s+x2-p)*t1]
while x1t[0]<0:
    x1t.pop(0)
while x2t[0]<x1t[0]:
    x2t.pop(0)
ans=min(ans,x2t[0])
print(ans)


from fractions import Fraction
# from math import ceil

s, x1, x2 = [int(v) for v in input().split()]
t1, t2 = [int(v) for v in input().split()]
p, d = [int(v) for v in input().split()]

# s, x1, x2 = 4,2,4
# t1, t2 = 3,4
# p, d = 1,1

# s, x1, x2 = 5,4,0
# t1, t2 = 1,2
# p, d = 3,1

if x1 > x2:
	x1, x2 = s - x1, s - x2
	p = s - p
	d = -d

if d == -1:
	p = -p
	d = 1
elif d == 1 and p > x1:
	p = -((s - p) + s)


if t2 <= t1:
	# print('a')
	print((x2 - x1) * t2)
else:
	# tram=t1, igor=t2
	# t = (x1 - p) * (t1 * t2) / (t2 - t1)
	meet = x1 + Fraction((x1 - p) * t1, t2 - t1)
	if x1 <= meet < x2:
		# print('b')
		print((x1 - p) * t1 + (x2 - x1) * t1)
	else:
		# print('c')
		print((x2 - x1) * t2)

#/usr/bin/env python3

import sys

def tram(inp):
    inp = list(map(int, inp.split()))
    s = inp[0]
    x1 = inp[1]
    x2 = inp[2]
    t1 = inp[3]
    t2 = inp[4]
    p = inp[5]
    d = inp[6]

    if d < 0:
        x1 = s-x1
        x2 = s-x2
        p = s - p

    walktime = abs(x1-x2)*t2

    if (x2 > x1):
        if (p > x1):
            tramtime = (s-p + s +x2) * t1
        else:
            tramtime = (x2 - p) *t1
    else: 
        tramtime = ((s-p) + s -x2) * t1

    return min(walktime, tramtime)


    







def __starting_point():
    inp = sys.stdin.read()
    inp = inp.strip()
    print(tram(inp))


__starting_point()

import sys

s, x1, x2 = list(map(int, sys.stdin.readline().split()))
t1, t2 = list(map(int, sys.stdin.readline().split()))
p, d = list(map(int, sys.stdin.readline().split()))

if x2 > x1:
    dp = 1
else:
    dp = -1

if dp == d:
    if d*p <= d*x1:
        dx2 = abs(x2 - p)
    else:
        if d == 1:
            dx2 = (s + (s-p) + x2)
        else:
            dx2 = (s + p + (s - x2))
else:
    if d == 1:
        dx2 = (2*s -p - x2)
    else:
        dx2 = p + x2

tt = dx2*t1
dx = abs(x1 - x2)
tp = t2 * dx

res = min(tp, tt)
print(res)



s, x1, x2 = map(int, input().split())
t1, t2 = map(int, input().split())
p, d = map(int, input().split())

ig = abs(x2 - x1) * t2

tr = ig
if d < 0:
    if x2 < x1:
        if x1 <= p:
            tr = (p - x2) * t1
        else:
            tr = (p + s + (s - x2)) * t1
    else:
        tr = (p + x2) * t1
else:
    if x1 < x2:
        if p <= x1:
            tr = (x2 - p) * t1
        else:
            tr = ((s - p) + s + x2) * t1
    else:
        tr = ((s - p) + (s - x2)) * t1

ans = min(ig, tr)

print(ans)

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 = (s - x1)
    x2 = (s - x2)
    p = (s - p)
    d = -d

vt = 1.0 / t1
vi = 1.0 / t2
xt0 = 0.0

if d == -1:
    xt0 = -p
elif p <= x1:
    xt0 = p
else:
    xt0 = -(s - p) - s

def solve(vt, xt0, vi, x1, x2):
    t1 = (x1 - xt0) / (vt - vi)
    t2 = (x2 - vi*t1 - x1) / vt
    t3 = (x1 - xt0) / (vt + vi)
    t4 = (x2 + vi*t3 - x1) / vt
    return min((x2-x1) / vi, min(t1 + t2, t3 + t4))

if t2 <= t1:
    print("%.0f" % ((x2 - x1) / vi))
else:
    print("%.0f" % solve(vt, xt0, vi, x1, x2))


from sys import stdin, stdout

s, x1, x2 = map(int, stdin.readline().split())
spt, spp = map(int, stdin.readline().split())
p, label = map(int, stdin.readline().split())
vt = 1 / spt
vp = 1 / spp

ans = abs(x2 - x1) * spp

if vt > vp:
    if label == 1:
        
        
        
        if x2 >= x1:
            if p <= x1:
                t = (x1 - p) / (vt - vp)
                ans = min(ans, t + max(x2 - (x1 + t * vp), 0) * spt)
            else:
                t = (s - p + s) / vt
                t += (x1 + t * vp) / (vt - vp)
                x1 += t * vp
                ans = min(ans, t + max(x2 - x1, 0) * spt)
        else:
            t = (s - p) / vt
            t += (s - (x1 - t * vp)) / (vt - vp)
            x1 -= t * vp
            ans = min(ans, t + max(x1 - x2, 0) * spt)
    else:
        
        if x2 <= x1:
            if p >= x1:
                t = (p - x1) / (vt - vp)
                ans = min(ans, t + max(x1 - t * vp - x2, 0) * spt)
            else:
                t = (p + s) * spt
                t += (s - (x1 - t * vp)) / (vt - vp)
                ans = min(ans, t + max(x1 - t * vp - x2, 0) * spt)
        else:
            t = p * spt
            t += (x1 + t * vp) / (vt - vp)
            x1 += t * vp
            ans = min(ans, t + max(x2 - x1, 0) * spt)
            
            
stdout.write(str(int(ans)))

import sys
from decimal import *

def check(t, w, s, p1, d1, p2, d2):
    if t*w >= 2*s:
        return True 




def main():

    s,a,b = list(map(int,sys.stdin.readline().split()))
    w,v = list(map(int,sys.stdin.readline().split()))
    p1,d = list(map(int,sys.stdin.readline().split()))

    r = abs(a-b)*v
    if v<=w:
        print(r)
        return

    if p1 <= a:
        t_=0
        if d==-1 and p1!=a:
            t_ = p1*w
            a = a - t_/v
            p1 = 0
            d=1
        t1 = (a-p1)*v*w/(v+w)
        x1 = a-t1/v
        t1+=t_ 
    else:
        t_=0
        if d==1:
            t_ = (s-p1)*w
            a = a + t_/v
            p1 = s
            d=-1
        t1 = (p1-a)*v*w/(v+w)
        x1 = a+t1/v
        t1+=t_
    if d==1:
        if x1 <=b:
            t2 = (b-x1)*w
        else:
            t2 = (2*s-x1-b)*w
    else:
        if x1 >=b:
            t2 = (x1-b)*w
        else:
            t2 = (x1+b)*w

    t3 = t1 + t2
    t3i = int(t3)
    if t3i < t3 - 0.000001:
        t3i+=1

    print(min(r, t3i))



main()


s , x1 , x2 = list(map(int, input().split()))
t1, t2= list(map(int, input().split()))
p, d= list(map(int, input().split()))
alt = abs(x1 - x2) * t2


curpos = p
curtime = 0
inbus = False
while not (curpos == x2 and inbus):
    if curpos == x1:
        inbus = True
    if curpos == s and d == 1:
        d = -1
    if curpos == 0 and d == -1:
        d = 1    
    if d == 1:
        curpos += 1
    else:
        curpos -= 1
    curtime += t1
print(min(curtime,alt))
        
     

        


s, x1, x2 = list(map(int, input().split()))
t1, t2 = list(map(int, input().split()))
p, d = list(map(int,input().split()))
wt = abs(x2-x1) * t2
if t2 <= t1:
    print(abs(x2-x1) * t2)
    return
tt = 0
if d == 1:
    if p <= x2:
        if x1 <= x2 and p <= x1:
            tt = abs(x2-p)*t1
        elif x1 > x2 and p <= x1:
            tt = (s - p + (s - x2))*t1
        elif x1 < p:
            tt = (s - p + s + x2)*t1
        else:
            raise Exception()
    else:
        if x1 > x2:
            tt = (s - p + s - x2) * t1
        else:
            tt = (s - p + s + x2) * t1
else:
    if p >= x2:
        if x1 >= x2 and p >= x1:
            tt = abs(x2-p)*t1
        elif x1 < x2 and p >= x1:
            tt = (p + x2)*t1
        elif x1 > p:
            tt = (p + s + s - x2)*t1
        else:
            raise Exception()
    else:
        if x1 < x2:
            tt = (p + x2) * t1
        else:
            tt = (p + s + s-x2) * t1

print(min(tt, wt))


def codeforces(max_point, start, finish, tram_speed, legs_speed,
               tram_point, direction):
    if tram_point == start:
        time_to_start = 0
    elif start > tram_point:
        if direction == 1:
            time_to_start = (start - tram_point) * tram_speed
        else:
            direction = -direction
            time_to_start = ((start - tram_point) * tram_speed +
                             tram_point * 2 * tram_speed)
    elif start < tram_point:
        if direction == -1:
            time_to_start = (tram_point - start) * tram_speed
        else:
            direction = -direction
            time_to_start = ((tram_point - start) * tram_speed +
                             (max_point - tram_point) * 2 * tram_speed)

    if start == finish:
        time_to_finish = 0
    elif finish > start:
        if direction == 1:
            time_to_finish = (finish - start) * tram_speed
        else:
            direction = -direction
            time_to_finish = ((finish - start) * tram_speed +
                              start * 2 * tram_speed)
    elif finish < start:
        if direction == -1:
            time_to_finish = (start - finish) * tram_speed
        else:
            direction = -direction
            time_to_finish = ((start - finish) * tram_speed +
                              (max_point - start) * 2 * tram_speed)

    tram_time = time_to_start + time_to_finish
    legs_time = abs(finish - start) * legs_speed
    return min(tram_time, legs_time)


max_point, start, finish = list(map(int, input().split()))
tram_speed, legs_speed = list(map(int, input().split()))
tram_point, direction = list(map(int, input().split()))

print((codeforces(max_point, start, finish, tram_speed, legs_speed,
                 tram_point, direction)))


s,x1,x2 = [int(i) for i in input().strip().split()]
t1,t2 = [int(i) for i in input().strip().split()]
p,d = [int(i) for i in input().strip().split()]

d2 = 1 if x2-x1>0 else -1
ans = abs(x2-x1)*t2

if d==d2==1:
  if p<=x1:
    ans = min(ans,(x2-p)*t1)
  elif p>x1:
    ans = min(ans,(2*s-p+x2)*t1)
elif d==d2==-1:
  if p>=x1:
    ans = min(ans,(p-x2)*t1)
  elif p<x1:
    ans = min(ans,(2*s+p-x2)*t1)
elif d!=d2 and d==1:
  ans = min(ans,(2*s-p-x2)*t1)
elif d!=d2 and d==-1:
  ans = min(ans,(p+x2)*t1)

print(ans)

s,x1,x2 = map(int, input().split(" "))
t1,t2 = map(int, input().split(" "))
p,d = map(int, input().split(" "))


if x2 > p and d == 1:
  train_dis = x2 - p
if x2 < p and d == 1:
  train_dis = s - p + s - x2
if x2 > p and d == -1:
  train_dis = p + x2
if x2 < p and d == -1:
  train_dis = p - x2

if x1 < x2 and p>x1 and p<x2 and d == 1:
  train_dis += 2 * s
if x1 < x2 and p>x1 and p>x2:
  train_dis += 2 * x2

if x1 > x2 and p > x2 and p < x1 and d == -1:
  train_dis += 2 * s
if x1 > x2 and p < x1 and p < x2:
  train_dis += 2 * (s-x2)


train_time = train_dis * t1

igor_dis  = abs(x2-x1)
igor_time = igor_dis * t2

print(min(igor_time, train_time))

s, x1, x2 = map(int, input().split())
t1, t2 = map(int, input().split())
p, d = map(int, input().split())

tp = abs(x1 - x2) * t2

if p != x1:
    v = False
else:
    v = True

tt = 0
while 1:
    if p == s:
        d = -1
    
    if p == 0:
        d = 1
        
    p += d
    tt += t1
    if p == x1:
        v = True
        
    if v and p == x2:
        break
print(min(tp, tt))

s,x1,x2 = map(int,input().split())
t1,t2 = map(int,input().split())
p,d = map(int,input().split())
ans = abs(x2-x1)*t2
xyz = abs(x2-x1)*t1
if x2 > x1:
    if d == 1:
        if p > x1:
            xyz += ((s-p)+(s)+(x1))*t1
        else:
            xyz += (x1-p)*t1
    else:
        xyz += (p+x1)*t1
else:
    if d == 1:
        xyz += ((s-p)+(s-x1))*t1
    else:
        if p >= x1:
            xyz += (p-x1)*t1
        else:
            xyz += ((p)+(s)+(s-x1))*t1
print(min(ans,xyz))