THE SPELL-BOUND WATER

0

0 votes
Problem

Harry potter has to find the “horcrux” as soon as possible so he decided to use a boat. The water was under the spell of the witches and flowed according to the direction which the witch wants.

He is currently at the point (x0, y0) and has to reach (x1, y1) in order to find the “horcrux”.

If spell is in direction U D,L,R, the water flows in directions  “up” ,”down”, ”left”, ”right” respectively (direction according to co-ordinate axis)

In a day, water  moves the boat by 1 unit in its direction .

In a day, Harry can go in either one of the four directions U,D,L,R by 1 unit or stay in place.

Transpositions of the direction desired by harry and the spell add up vectorially

 

The spell by witch is periodic for period of n days. On the  (n+1)th day spell is same as spell at 1st  day.

 

For example,

if water(under spell) is in direction ‘U’ and the harry's direction is L, then from point (x, y) ,boat will move to the point (x−1,y+1),

if water(under spell) is in direction ‘U’ and the harry's direction is ‘U’, then from point (x, y) boat will move to the point (x,y+2),

if water(under spell) is in direction ‘U’ and the harry wants to stay, then from point (x, y) boat will move to the point (x,y+1),

Help Harry to find the minimum days in which he can reach destination if possible.

 

Input

The first line contains two integers x0, y0 ( 0≤ x0,y0 ≤ 10^9) –Harry’s  initial coordinates

The second line contains two integers x1, y1 (0≤ x1, y1  ≤10^9) — final  co-ordinates Harry need to reach.

Initial coordinates and destination point coordinates are different.

The third line contains a single integer n (1 ≤ n ≤ 10 ^ 5) — the length of the string s denoting spell of witch.

The fourth line contains the string s denoting the ‘n days periodic’ spell of witch, consisting only of letters U, D, L and R.

 

Output

The only line should contain the minimal number of days required for the boat to reach the point (x1,y1).

If it is impossible then print "-1".

Time Limit: 2
Memory Limit: 256
Source Limit:
Explanation

x0,y0=(0,0)

x1,y1=(2,2)

Harry should move as direction specified "UUUUUU"

spell being preiodic after 3 days , DDRDDR...

1st day:  U and D cancels , coordinates = (0,0)

2nd day :U and D cancels  ,coordinates = (0,0)

3rd day:  U and R add  up  ,coordinates = (1,1)

4th day :  U and D cancels ,coordinates = (1,1)

5th day :  U and D cancels ,coordinates = (1,1)

6th day: U and R add up ,coordinates = (2,2)

Editor Image

?