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;
const int INF = 0x3fffffff;
const int SINF = 0x7fffffff;
const long long LINF = 0x3fffffffffffffff;
const long long SLINF = 0x7fffffffffffffff;
const int MAXN = 100007;
struct cT {
  cT() {}
  cT(int _x, int _y) { setd(_x, _y); }
  void setd(int _x, int _y) { x = _x, y = _y; }
  bool operator<(const cT &a) const { return x < a.x; }
  int x, y;
};
int MOVE[4][2] = {-1, -1, -1, 1, 1, -1, 1, 1};
int n, m, k;
set<cT> mul[MAXN * 2], mur[MAXN * 2];
set<cT>::iterator it;
int cx[MAXN], cy[MAXN];
int ox, oy, odir, nx, ny, dir, tx, ty, tdir;
bool flag;
void init();
void input();
void work();
int getidl(int x, int y);
int getidr(int x, int y);
int move();
int main() {
  init();
  input();
  work();
}
void init() { ios::sync_with_stdio(false); }
void input() {
  scanf("%d%d%d", &n, &m, &k);
  for (int i = 0; i < k; ++i) scanf("%d%d", &cx[i], &cy[i]);
  char s[5];
  scanf("%d%d%s", &ox, &oy, s);
  odir = 0;
  if (s[0] == 'S') odir += 2;
  if (s[1] == 'E') ++odir;
}
void work() {
  for (int i = 0; i <= n + 1; ++i) {
    mul[getidl(i, 0)].insert(cT(i, 0));
    mul[getidl(i, m + 1)].insert(cT(i, m + 1));
    mur[getidr(i, 0)].insert(cT(i, 0));
    mur[getidr(i, m + 1)].insert(cT(i, m + 1));
  }
  for (int i = 0; i <= m + 1; ++i) {
    mul[getidl(0, i)].insert(cT(0, i));
    mul[getidl(n + 1, i)].insert(cT(n + 1, i));
    mur[getidr(0, i)].insert(cT(0, i));
    mur[getidr(n + 1, i)].insert(cT(n + 1, i));
  }
  for (int i = 0; i < k; ++i) {
    mul[getidl(cx[i], cy[i])].insert(cT(cx[i], cy[i]));
    mur[getidr(cx[i], cy[i])].insert(cT(cx[i], cy[i]));
  }
  flag = false;
  bool runned;
  nx = ox, ny = oy, dir = odir;
  move();
  tx = nx, ty = ny, tdir = dir;
  runned = false;
  long long ans = 0;
  while (!flag && (!runned || !(nx == tx && ny == ty && dir == tdir))) {
    runned = true;
    ans += move();
    if (flag) break;
  }
  if (flag) {
    nx = ox, ny = oy, dir = odir;
    ans += move();
    nx = ox, ny = oy, dir = odir ^ 3;
    flag = false;
    ans += move();
    tx = nx, ty = ny, tdir = dir;
    runned = false;
    while (!flag && !runned || !(nx == tx && ny == ty && dir == tdir)) {
      runned = true;
      ans += move();
      if (flag) break;
    }
    --ans;
  }
  printf("%I64d\n", ans);
}
int move() {
  int vx, vy;
  if (!((dir & 1) ^ ((dir & 2) >> 1))) {
    int nid = getidl(nx, ny);
    it = mul[nid].upper_bound(cT(nx, ny));
    if (!(dir & 2)) --it;
  } else {
    int nid = getidr(nx, ny);
    it = mur[nid].upper_bound(cT(nx, ny));
    if (!(dir & 2)) --it;
  }
  vx = it->x - MOVE[dir][0], vy = it->y - MOVE[dir][1];
  int ans = (((vx - nx) >= 0) ? (vx - nx) : (-(vx - nx))) + 1;
  int nid = getidl(vx + MOVE[dir][0], vy);
  bool dxv = (mul[nid].find(cT(vx + MOVE[dir][0], vy)) != mul[nid].end());
  nid = getidl(vx, vy + MOVE[dir][1]);
  bool dyv = (mul[nid].find(cT(vx, vy + MOVE[dir][1])) != mul[nid].end());
  nx = vx, ny = vy;
  if (!(dxv ^ dyv))
    flag = true;
  else {
    if (dxv) {
      ny += MOVE[dir][1];
      dir ^= 2;
    } else {
      nx += MOVE[dir][0];
      dir ^= 1;
    }
  }
  return ans;
}
int getidl(int x, int y) {
  int id = y - x + 1;
  if (id < 0) id += MAXN;
  return id;
}
int getidr(int x, int y) { return (x + y + 1); }