#P2689. 东南西北

东南西北

Description

Given the coordinates of the start and end points, and the wind direction (east, south, west, north) at each of the next TT time steps, you may either move 11 unit with the wind or stay in place at each time step. Find the minimum number of moves needed to reach the destination.

The coordinate system is the Cartesian plane, where the positive xx-axis points east and the positive yy-axis points north.

If it is impossible to reach the destination, output 1-1.

Input Format

The first line contains two positive integers x1,y1x_1, y_1, representing Xiaoming’s current position.

The second line contains two positive integers x2,y2x_2, y_2, representing the position Xiaoming wants to reach.

The third line contains an integer TT, representing TT time steps.

From line 44 to line T+3T+3, each line contains one character representing the wind direction, i.e., the first letter of the English words for east (E\verb!E!), south (S\verb!S!), west (W\verb!W!), and north (N\verb!N!).

Output Format

Output a single integer, the minimum number of moves.

1 1
2 2
5
E
N
W
W
N
2
1 1
2 2
1
W
-1
1 1
2 2
3
W
W
W
-1

Hint

Sample Explanation

  • Sample 11: Move one step east, then one step north.
  • Samples 22 and 33: Impossible to reach.

Constraints

For all testdata, 1T501 \le T \le 50.

Translated by ChatGPT 5