Magic Ship

Magic Ship
You a captain of a ship. Initially you are standing in a point (x1,y1) (obviously, all positions in the sea can be described by cartesian plane) and you want to travel to a point (x2,y2).

You know the weather forecast — the string s of length n, consisting only of letters U, D, L and R. The letter corresponds to a direction of wind. Moreover, the forecast is periodic, e.g. the first day wind blows to the side s1, the second day — s2, the n-th day — sn and (n+1)-th day — s1 again and so on.

Ship coordinates change the following way:

if wind blows the direction U, then the ship moves from (x,y) to (x,y+1);
if wind blows the direction D, then the ship moves from (x,y) to (x,y−1);
if wind blows the direction L, then the ship moves from (x,y) to (x−1,y);
if wind blows the direction R, then the ship moves from (x,y) to (x+1,y).
The ship can also either go one of the four directions or stay in place each day. If it goes then it’s exactly 1 unit of distance. Transpositions of the ship and the wind add up. If the ship stays in place, then only the direction of wind counts. For example, if wind blows the direction U and the ship moves the direction L, then from point (x,y) it will move to the point (x−1,y+1), and if it goes the direction U, then it will move to the point (x,y+2).

You task is to determine the minimal number of days required for the ship to reach the point (x2,y2).

Input
The first line contains two integers x1,y1 (0≤x1,y1≤109) — the initial coordinates of the ship.

The second line contains two integers x2,y2 (0≤x2,y2≤109) — the coordinates of the destination point.

It is guaranteed that the initial coordinates and destination point coordinates are different.

The third line contains a single integer n (1≤n≤105) — the length of the string s.

The fourth line contains the string s itself, consisting only of letters U, D, L and R.

Output
The only line should contain the minimal number of days required for the ship to reach the point (x2,y2).

If it’s impossible then print “-1”.

Examples
Input
0 0
4 6
3
UUU
Output
5
Input
0 3
0 0
3
UDD
Output
3
Input
0 0
0 1
1
L
Output
-1
Note
In the first example the ship should pe

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值