P28300 [洛谷] North South East West
普及-
题目描述

Problem Description

Given the coordinates of the starting point and the destination, as well as the wind directions (North, South, East, West) for the next $T$ moments, you can choose to move $1$ unit in the direction of the wind or stay in place at each moment. Find the minimum number of moves required to reach the destination.

The coordinates use a Cartesian coordinate system, with the positive $x$-axis pointing east and the positive $y$-axis pointing north.

If it is not possible to move to the destination, output $-1$.

Input Format

The first line contains two positive integers $x_1, y_1$, representing the position of the starting point.

The second line contains two positive integers $x_2, y_2$, representing the position of the destination.

The third line contains an integer $T$, representing the number of moments.

From the fourth to the $N+3$th line, each line contains a character representing the wind direction, which is the first letter of the English word for East ($\verb!E!$), South ($\verb!S!$), West ($\verb!W!$), or North ($\verb!N!$).

Output Format

A single line containing an integer, representing the minimum number of moves.

Sample Input and Output

Sample Input #1

1 1
2 2
5
E
N
W
W
N

Sample Output #1

2

Sample Input #2

1 1
2 2
1
W

Sample Output #2

-1

Sample Input #3

1 1
2 2
3
W
W
W

Sample Output #3

-1

Notes

Sample Explanation

  • Sample $1$: Move one step east and one step north.
  • Samples $2$ and $3$: It is not possible to reach the destination.

Data Range

For all data, $1 \le T \le 50$.

输入格式

见题面 Input 部分

输出格式

见题面 Output 部分

样例输入
1 1 2 2 5 E N W W N
样例输出
2