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 MOD = 1e9 + 7;
const long long LINF = 2e16;
const int INF = 2e9;
const int magic = 348;
const double eps = 1e-10;
const double pi = 3.14159265;
inline int getint() {
  char ch;
  int res;
  bool f;
  while (!isdigit(ch = getchar()) && ch != '-') {
  }
  if (ch == '-')
    f = false, res = 0;
  else
    f = true, res = ch - '0';
  while (isdigit(ch = getchar())) res = res * 10 + ch - '0';
  return f ? res : -res;
}
int n, m, k;
pair<int, int> stone[800048];
const int base = 150048;
set<pair<int, int> > pos[800048], neg[800048];
bool has[800048][5];
int from[800048][5];
long long ans = 0;
int rev = 0;
bool superf, revf, goodstart;
inline int myabs(int first) { return first >= 0 ? first : -first; }
void doit(int first, int second, int dir) {
  int tox, toy, toind;
  if (dir == 1 || dir == 3) {
    set<pair<int, int> >::iterator iter;
    iter = neg[first + second].lower_bound(make_pair(first, -1));
    if (dir == 1) {
      iter--;
      tox = iter->first;
      toy = first + second - tox;
      tox++;
      toy--;
      toind = iter->second;
      if (from[toind][dir]) {
        superf = true;
        ans += myabs(from[toind][dir] - first);
        return;
      }
      ans += myabs(tox - first) + 1;
      from[toind][dir] = first;
      if ((has[toind][3] && has[toind][4]) ||
          (!has[toind][3] && !has[toind][4])) {
        rev++;
        revf = true;
        return;
      }
      if (has[toind][3]) {
        doit(tox - 1, toy, 4);
        if (superf || revf) return;
      } else {
        doit(tox, toy + 1, 2);
        if (superf || revf) return;
      }
    } else {
      tox = iter->first;
      toy = first + second - tox;
      tox--;
      toy++;
      toind = iter->second;
      if (from[toind][dir]) {
        superf = true;
        ans += myabs(from[toind][dir] - first);
        return;
      }
      ans += myabs(tox - first) + 1;
      from[toind][dir] = first;
      if ((has[toind][1] && has[toind][2]) ||
          (!has[toind][1] && !has[toind][2])) {
        rev++;
        revf = true;
        return;
      }
      if (has[toind][1]) {
        doit(tox + 1, toy, 2);
        if (superf || revf) return;
      } else {
        doit(tox, toy - 1, 4);
        if (superf || revf) return;
      }
    }
  } else {
    set<pair<int, int> >::iterator iter;
    iter = pos[base + first - second].lower_bound(make_pair(first, -1));
    if (dir == 4) {
      iter--;
      tox = iter->first;
      toy = tox - (first - second);
      tox++;
      toy++;
      toind = iter->second;
      if (from[toind][dir]) {
        superf = true;
        ans += myabs(from[toind][dir] - first);
        return;
      }
      ans += myabs(tox - first) + 1;
      from[toind][dir] = first;
      if ((has[toind][2] && has[toind][3]) ||
          (!has[toind][2] && !has[toind][3])) {
        rev++;
        revf = true;
        return;
      }
      if (has[toind][2]) {
        doit(tox, toy - 1, 3);
        if (superf || revf) return;
      } else {
        doit(tox - 1, toy, 1);
        if (superf || revf) return;
      }
    } else {
      tox = iter->first;
      toy = tox - (first - second);
      tox--;
      toy--;
      toind = iter->second;
      if (from[toind][dir]) {
        superf = true;
        ans += myabs(from[toind][dir] - first);
        return;
      }
      ans += myabs(tox - first) + 1;
      from[toind][dir] = first;
      if ((has[toind][1] && has[toind][4]) ||
          (!has[toind][1] && !has[toind][4])) {
        rev++;
        revf = true;
        return;
      }
      if (has[toind][1]) {
        doit(tox + 1, toy, 3);
        if (superf || revf) return;
      } else {
        doit(tox, toy + 1, 1);
        if (superf || revf) return;
      }
    }
  }
}
int main() {
  int i, cc = 0;
  n = getint();
  m = getint();
  k = getint();
  for (i = 1; i <= k; i++) {
    stone[i].first = getint();
    stone[i].second = getint();
    pos[base + stone[i].first - stone[i].second].insert(
        make_pair(stone[i].first, i));
    neg[stone[i].first + stone[i].second].insert(make_pair(stone[i].first, i));
  }
  cc = k;
  for (i = 1; i <= m; i++) {
    stone[++cc] = make_pair(0, i);
    pos[base + stone[cc].first - stone[cc].second].insert(
        make_pair(stone[cc].first, cc));
    neg[stone[cc].first + stone[cc].second].insert(
        make_pair(stone[cc].first, cc));
    stone[++cc] = make_pair(n + 1, i);
    pos[base + stone[cc].first - stone[cc].second].insert(
        make_pair(stone[cc].first, cc));
    neg[stone[cc].first + stone[cc].second].insert(
        make_pair(stone[cc].first, cc));
  }
  for (i = 1; i <= n; i++) {
    stone[++cc] = make_pair(i, 0);
    pos[base + stone[cc].first - stone[cc].second].insert(
        make_pair(stone[cc].first, cc));
    neg[stone[cc].first + stone[cc].second].insert(
        make_pair(stone[cc].first, cc));
    stone[++cc] = make_pair(i, m + 1);
    pos[base + stone[cc].first - stone[cc].second].insert(
        make_pair(stone[cc].first, cc));
    neg[stone[cc].first + stone[cc].second].insert(
        make_pair(stone[cc].first, cc));
  }
  stone[++cc] = make_pair(0, 0);
  pos[base + stone[cc].first - stone[cc].second].insert(
      make_pair(stone[cc].first, cc));
  neg[stone[cc].first + stone[cc].second].insert(
      make_pair(stone[cc].first, cc));
  stone[++cc] = make_pair(0, m + 1);
  pos[base + stone[cc].first - stone[cc].second].insert(
      make_pair(stone[cc].first, cc));
  neg[stone[cc].first + stone[cc].second].insert(
      make_pair(stone[cc].first, cc));
  stone[++cc] = make_pair(n + 1, 0);
  pos[base + stone[cc].first - stone[cc].second].insert(
      make_pair(stone[cc].first, cc));
  neg[stone[cc].first + stone[cc].second].insert(
      make_pair(stone[cc].first, cc));
  stone[++cc] = make_pair(n + 1, m + 1);
  pos[base + stone[cc].first - stone[cc].second].insert(
      make_pair(stone[cc].first, cc));
  neg[stone[cc].first + stone[cc].second].insert(
      make_pair(stone[cc].first, cc));
  set<pair<int, int> >::iterator iter, iter2;
  for (i = 1; i <= n + m + 2; i++)
    for (iter = neg[i].begin(); iter != neg[i].end(); iter++) {
      if (iter->first != 1) {
        iter2 = neg[i - 1].lower_bound(make_pair(iter->first - 1, -1));
        if (iter2 != neg[i - 1].end() && iter2->first == iter->first - 1)
          has[iter->second][1] = true;
      }
      if (iter->first != n) {
        iter2 = neg[i + 1].lower_bound(make_pair(iter->first + 1, -1));
        if (iter2 != neg[i + 1].end() && iter2->first == iter->first + 1)
          has[iter->second][3] = true;
      }
      if (stone[iter->second].second != 1) {
        iter2 = neg[i - 1].lower_bound(make_pair(iter->first, -1));
        if (iter2 != neg[i - 1].end() && iter2->first == iter->first)
          has[iter->second][4] = true;
      }
      if (stone[iter->second].second != m) {
        iter2 = neg[i + 1].lower_bound(make_pair(iter->first, -1));
        if (iter2 != neg[i + 1].end() && iter2->first == iter->first)
          has[iter->second][2] = true;
      }
    }
  int sx, sy, sdir;
  string type;
  sx = getint();
  sy = getint();
  cin >> type;
  if (type == "NE") sdir = 1;
  if (type == "SE") sdir = 2;
  if (type == "SW") sdir = 3;
  if (type == "NW") sdir = 4;
  doit(sx, sy, sdir);
  if (superf) {
    cout << ans << endl;
    return 0;
  } else {
    superf = revf = false;
    if (sdir == 1) doit(sx, sy, 3);
    if (sdir == 2) doit(sx, sy, 4);
    if (sdir == 3) doit(sx, sy, 1);
    if (sdir == 4) doit(sx, sy, 2);
    cout << ans - 1 << endl;
    return 0;
  }
}