time limit per test1 second

memory limit per test256 megabytes

inputstandard input

outputstandard output

The tram in Berland goes along a straight line from the point 0 to the point s and back, passing 1 meter per t1 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 x1. He should reach the point x2. Igor passes 1 meter per t2 seconds.

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

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 t2 seconds). He can also stand at some point for some time.

Input

The first line contains three integers s, x1 and x2 (2 ≤ s ≤ 1000, 0 ≤ x1, x2 ≤ s, x1 ≠ x2) — 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 t1 and t2 (1 ≤ t1, t2 ≤ 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 ) — the position of the tram in the moment Igor came to the point x1 and the direction of the tram at this moment. If , 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 x1 to the point x2.

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 x2 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 x2 in 7 seconds in total.

【题目链接】:http://codeforces.com/contest/746

【题解】



按照要求、其实就是比较车先到X2还是人先到X2;

但是单纯这样做就太天真了,会在第3个点WA(路人甲:为什么你知道?)

要考虑那种车到了X2但是人还上不了车的情况。

是不是恍然大悟??

对x2,x1,P的相对位置分类讨论一下就可以了。

(有一个地方忘记乘上时间、WA第19个点TAT);



【完整代码】

#include <bits/stdc++.h>
using namespace std;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define rei(x) scanf("%d",&x)
#define rel(x) scanf("%I64d",&x) typedef pair<int,int> pii;
typedef pair<LL,LL> pll; //const int MAXN = x;
const int dx[9] = {0,1,-1,0,0,-1,-1,1,1};
const int dy[9] = {0,0,0,-1,1,-1,1,-1,1};
const double pi = acos(-1.0); int s,x1,x2,t1,t2,p,d;
int car = 0; int main()
{
//freopen("F:\\rush.txt","r",stdin);
rei(s);rei(x1);rei(x2);
rei(t1);rei(t2);
rei(p);rei(d);
if (p < x2)
{
if (d==1)
{
if (x1>x2)
car = (s-p+s-x2)*t1;
else
if (x1<x2)
{
if (x1>=p)
car = (x2-p)*t1;
else
if (x1<p)
car = (s-p+s+x2)*t1;
}
}
else
{
if (x1 <x2)
car = (p+x2)*t1;
else
if (x1 > x2)
car = (p+s+s-x2)*t1;
}
}
else
if (p>x2)
{
if (d==1)
{
if (x1<x2)
{
car = (s-p+s+x2)*t1;
}
else
if (x1>x2)
car = (s-p+s-x2)*t1;
}
else
{
if (x1<x2)
car = (p+x2)*t1;
else
if (x1>x2)
{
if (x1<=p)
car = (p-x2)*t1;
else
if (x1>p)
car = (p+s+s-x2)*t1;
}
}
}
int peo;
peo = abs(x2-x1)*t2;
cout << min(peo,car);
return 0;
}

最新文章

  1. 静态绑定网关,防止ARP攻击
  2. Android应用开发是否应避免使用枚举?
  3. JS,html压缩及混淆工具
  4. window通过mstsc远程连接其它计算机
  5. Sql 数据引擎中删除用户名、密码信息
  6. Peer-to-Peer 综述
  7. range-bar
  8. 【典型错误】The type java.lang.Object cannot be resolved.
  9. Linux进程间通信——使用信号
  10. Android_Dialog cancle 和dismiss 区别
  11. netfilter/iptables和firewalld的关系
  12. Web安全学习计划
  13. ArcPy 批量给shp字段赋值
  14. board_key.h/board_key.c
  15. Xamarin + MvvmCross 简单事例 Part 2
  16. 用VSCode的debugger for chrome插件调试服务器项目的配置方式
  17. linux下的shell脚本的使用
  18. zookeeper-01 概述
  19. Aspose.Words三 创建表格
  20. TFS支持移动设备,微软已经走出了第一步(手机上更新、查询工作项)

热门文章

  1. js将canvas保存成图片并下载
  2. Kubernetes1.4即将发布
  3. SSH applicationContext.xml import异常
  4. 百度语音识别REST API用法(含JAVA代码)——不须要集成SDK的方法
  5. 开窗函数over()中partition by关键字解析
  6. ps学习教程
  7. vue插件大全
  8. 控制台输入聊天记录 输出到文件中保存 Day20
  9. 9-1进程,进程池和socketserver
  10. notepad++最有用的快捷键