Problem: Imagine an n × m grid with some blocked cells. The top left cell in the grid has coordinates (1, 1) and the bottom right cell has coordinates (n, m). There are k blocked cells in the grid and others are empty. You flash a laser beam from the center of an empty cell (xs, ys) in one of the diagonal directions (i.e. north-east, north-west, south-east or south-west). If the beam hits a blocked cell or the border of the grid it will reflect. The behavior of the beam reflection in different situations is depicted in the figure below. 

<image>

After a while the beam enters an infinite cycle. Count the number of empty cells that the beam goes through at least once. We consider that the beam goes through cell if it goes through its center.

Input

The first line of the input contains three integers n, m and k (1 ≤ n, m ≤ 105, 0 ≤ k ≤ 105). Each of the next k lines contains two integers xi and yi (1 ≤ xi ≤ n, 1 ≤ yi ≤ m) indicating the position of the i-th blocked cell. 

The last line contains xs, ys (1 ≤ xs ≤ n, 1 ≤ ys ≤ m) and the flash direction which is equal to "NE", "NW", "SE" or "SW". These strings denote directions ( - 1, 1), ( - 1, - 1), (1, 1), (1, - 1).

It's guaranteed that no two blocked cells have the same coordinates.

Output

In the only line of the output print the number of empty cells that the beam goes through at least once.

Please, do not write the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier.

Examples

Input

3 3 0
1 2 SW


Output

6


Input

7 5 3
3 3
4 3
5 3
2 1 SE


Output

14

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
int n, m, k, now;
map<int, int> bo[110000], prego[5][110000];
struct atom {
  int x, y;
};
int operator<(atom k1, atom k2) { return k1.x < k2.x; }
set<atom> A[210000], B[210000];
int where1, where2, s1, s2, len, a[210000], lim = n + m;
char ch[10];
struct line {
  int x1, y1, x2, y2;
};
int operator<(const line k1, const line k2) { return k1.x1 < k2.x1; }
vector<line> C[210000], D[210000], c[210000], d;
struct atom2 {
  int x, y, w;
} y[210000];
int compare(atom2 k1, atom2 k2) { return k1.x + k1.y < k2.x + k2.y; };
void add(int k1, int k2) {
  for (; k1 <= lim; k1 += k1 & (-k1)) a[k1] += k2;
}
int find(int k) {
  int num = 0;
  for (; k; k -= k & (-k)) num += a[k];
  return num;
}
int main() {
  scanf("%d%d%d", &n, &m, &k);
  for (int i = 1; i <= k; i++) {
    int k1, k2;
    scanf("%d%d", &k1, &k2);
    bo[k1][k2] = 1;
    A[k1 + k2].insert((atom){k1, k2});
    B[k1 - k2 + m + 1].insert((atom){k1, k2});
  }
  scanf("%d%d", &where1, &where2);
  scanf("%s", ch + 1);
  s1 = where1;
  s2 = where2;
  if (ch[1] == 'N' && ch[2] == 'E')
    now = 1;
  else if (ch[1] == 'N' && ch[2] == 'W')
    now = 2;
  else if (ch[1] == 'S' && ch[2] == 'E')
    now = 3;
  else
    now = 4;
  int pre = now, flag = 0, ti = 0;
  for (int i = 0; i <= n + 1; i++) {
    bo[i][0] = 1;
    bo[i][m + 1] = 1;
    int k1 = i, k2 = 0;
    A[k1 + k2].insert((atom){k1, k2});
    B[k1 - k2 + m + 1].insert((atom){k1, k2});
    k1 = i;
    k2 = m + 1;
    A[k1 + k2].insert((atom){k1, k2});
    B[k1 - k2 + m + 1].insert((atom){k1, k2});
  }
  for (int i = 0; i <= m + 1; i++) {
    bo[0][i] = 1;
    bo[n + 1][i] = 1;
    int k1 = 0, k2 = i;
    A[k1 + k2].insert((atom){k1, k2});
    B[k1 - k2 + m + 1].insert((atom){k1, k2});
    k1 = n + 1;
    k2 = i;
    A[k1 + k2].insert((atom){k1, k2});
    B[k1 - k2 + m + 1].insert((atom){k1, k2});
  }
  while (1) {
    if (prego[now][where1][where2]) break;
    prego[now][where1][where2] = 1;
    if (now == 1) {
      set<atom>::iterator k1 =
          A[where1 + where2].lower_bound((atom){where1, 0});
      int x, y, next, X, Y;
      if (k1 == A[where1 + where2].begin()) {
        int dis = min(where1 - 1, m - where2);
        x = where1 - dis;
        y = where2 + dis;
        X = x;
        Y = y;
        if (x == 1) {
          if (y == m)
            next = 4;
          else {
            next = 3;
            Y++;
          }
        } else {
          next = 2;
          X--;
        }
      } else {
        k1--;
        x = (*k1).x + 1;
        y = (*k1).y - 1;
        X = x;
        Y = y;
        if (bo[x - 1][y]) {
          if (bo[x][y + 1])
            next = 4;
          else
            next = 3;
        } else if (bo[x][y + 1])
          next = 2;
        else
          next = 4;
        if (next == 3)
          Y++;
        else if (next == 2)
          X--;
      }
      C[where1 + where2].push_back((line){x, y, where1, where2});
      now = next;
      where1 = X;
      where2 = Y;
      continue;
    } else if (now == 2) {
      set<atom>::iterator k1 =
          B[where1 - where2 + m + 1].lower_bound((atom){where1, 0});
      int x, y, next, X, Y;
      if (k1 == B[where1 - where2 + m + 1].begin()) {
        int dis = min(where1 - 1, where2 - 1);
        x = where1 - dis;
        y = where2 - dis;
        X = x;
        Y = y;
        if (x == 1) {
          if (y == 1)
            next = 3;
          else {
            next = 4;
            Y--;
          }
        } else {
          next = 1;
          X--;
        }
      } else {
        k1--;
        x = (*k1).x + 1;
        y = (*k1).y + 1;
        X = x;
        Y = y;
        if (bo[x - 1][y]) {
          if (bo[x][y - 1])
            next = 3;
          else
            next = 4;
        } else if (bo[x][y - 1])
          next = 1;
        else
          next = 3;
        if (next == 4)
          Y--;
        else if (next == 1)
          X--;
      }
      D[where1 - where2 + m].push_back((line){x, y, where1, where2});
      now = next;
      where1 = X;
      where2 = Y;
      continue;
    } else if (now == 3) {
      set<atom>::iterator k1 =
          B[where1 - where2 + m + 1].upper_bound((atom){where1, 0});
      int x, y, next, X, Y;
      if (k1 == B[where1 - where2 + m + 1].end()) {
        int dis = min(n - where1, m - where2);
        x = where1 + dis;
        y = where2 + dis;
        X = x;
        Y = y;
        if (x == n) {
          if (y == m)
            next = 2;
          else {
            next = 1;
            Y++;
          }
        } else {
          next = 4;
          X++;
        }
      } else {
        x = (*k1).x - 1, y = (*k1).y - 1;
        X = x;
        Y = y;
        if (bo[x][y + 1]) {
          if (bo[x + 1][y])
            next = 2;
          else
            next = 4;
        } else if (bo[x + 1][y])
          next = 1;
        else
          next = 2;
        if (next == 1)
          Y++;
        else if (next == 4)
          X++;
      }
      D[where1 - where2 + m].push_back((line){where1, where2, x, y});
      now = next;
      where1 = X;
      where2 = Y;
      continue;
    } else if (now == 4) {
      set<atom>::iterator k1 =
          A[where1 + where2].upper_bound((atom){where1, 0});
      int x, y, next, X, Y;
      if (k1 == A[where1 + where2].end()) {
        int dis = min(n - where1, where2 - 1);
        x = where1 + dis;
        y = where2 - dis;
        X = x;
        Y = y;
        if (x == n) {
          if (y == 1)
            next = 1;
          else {
            next = 2;
            Y--;
          }
        } else {
          next = 3;
          X++;
        }
      } else {
        x = (*k1).x - 1;
        y = (*k1).y + 1;
        X = x;
        Y = y;
        if (bo[x + 1][y]) {
          if (bo[x][y - 1])
            next = 1;
          else
            next = 2;
        } else if (bo[x][y - 1])
          next = 3;
        else
          next = 1;
        if (next == 2)
          Y--;
        else if (next == 3)
          X++;
      }
      C[where1 + where2].push_back((line){where1, where2, x, y});
      now = next;
      where1 = X;
      where2 = Y;
      continue;
    }
  }
  long long ans = 0;
  for (int i = 1; i <= n + m; i++) {
    if (C[i].size() == 0) continue;
    sort(C[i].begin(), C[i].end());
    int pre = C[i][0].x1, now = C[i][0].x2;
    for (int j = 1; j < C[i].size(); j++)
      if (C[i][j].x1 > now) {
        ans += now - pre + 1;
        pre = C[i][j].x1;
        now = C[i][j].x2;
      } else
        now = max(C[i][j].x2, now);
    ans += now - pre + 1;
  }
  for (int i = 1; i <= n + m; i++) {
    if (D[i].size() == 0) continue;
    sort(D[i].begin(), D[i].end());
    int pre = D[i][0].x1, now = D[i][0].x2;
    for (int j = 1; j < D[i].size(); j++)
      if (D[i][j].x1 > now) {
        ans += now - pre + 1;
        pre = D[i][j].x1;
        now = D[i][j].x2;
      } else
        now = max(D[i][j].x2, now);
    ans += now - pre + 1;
  }
  cout << ans << endl;
  return 0;
}