Problem: Petya has a polygon consisting of n vertices. All sides of the Petya's polygon are parallel to the coordinate axes, and each two adjacent sides of the Petya's polygon are perpendicular. It is guaranteed that the polygon is simple, that is, it doesn't have self-intersections and self-touches. All internal area of the polygon (borders are not included) was painted in black color by Petya.

Also, Petya has a rectangular window, defined by its coordinates, through which he looks at the polygon. A rectangular window can not be moved. The sides of the rectangular window are parallel to the coordinate axes.

<image> Blue color represents the border of a polygon, red color is the Petya's window. The answer in this case is 2.

Determine the number of black connected areas of Petya's polygon, which can be seen through the rectangular window.

Input

The first line contain four integers x_1, y_1, x_2, y_2 (x_1 < x_2, y_2 < y_1) — the coordinates of top-left and bottom-right corners of the rectangular window. 

The second line contains a single integer n (4 ≤ n ≤ 15 000) — the number of vertices in Petya's polygon.

Each of the following n lines contains two integers — the coordinates of vertices of the Petya's polygon in counterclockwise order. Guaranteed, that the given polygon satisfies the conditions described in the statement.

All coordinates of the rectangular window and all coordinates of the vertices of the polygon are non-negative and do not exceed 15 000.

Output

Print the number of black connected areas of Petya's polygon, which can be seen through the rectangular window.

Example

Input

5 7 16 3
16
0 0
18 0
18 6
16 6
16 1
10 1
10 4
7 4
7 2
2 2
2 6
12 6
12 12
10 12
10 8
0 8


Output

2

Note

The example corresponds to the picture above.

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
const int sz = 2e4;
struct pt {
  int x, y;
};
pt ar[sz];
vector<int> sv[sz];
bool comp(int a, int b) { return ar[a].y < ar[b].y; }
bool comp2(int a, int b) { return ar[a].x < ar[b].x; }
bool us[sz];
void dfs(int v) {
  us[v] = 1;
  for (int a = 0; a < sv[v].size(); a++) {
    int ne = sv[v][a];
    if (us[ne] == 0) dfs(ne);
  }
}
int main() {
  int n, xl, yl, xr, yr, q = 0;
  cin >> xl >> yr >> xr >> yl >> n;
  for (int a = 0; a < n; a++) cin >> ar[a].x >> ar[a].y;
  vector<int> ve, ve2;
  for (int a = 0; a < n; a++) {
    pt p1 = ar[a], p2 = ar[(a + 1) % n];
    if (p1.y == p2.y and p1.y > yl and p1.y < yr and min(p1.x, p2.x) <= xl and
        max(p1.x, p2.x) > xl)
      ve2.push_back(a);
    if (p1.x == p2.x and p1.x > xl and p1.x < xr and
        max(yl, min(p1.y, p2.y)) < min(yr, max(p1.y, p2.y)))
      ve.push_back(a);
  }
  map<int, pair<int, int> > se;
  sort(ve2.begin(), ve2.end(), comp);
  if (ve2.size() == 0) {
    bool inter = 0;
    for (int a = 1; a < n; a++) {
      pt p1 = ar[a], p2 = ar[(a + 1) % n];
      if (p1.y == p2.y and p1.y >= yr and min(p1.x, p2.x) < xl and
          xl < max(p1.x, p2.x))
        inter ^= 1;
      if (p1.x == p2.x and p1.x == xl and max(p1.y, p2.y) >= yr) {
        pt p3 = ar[(a + n - 1) % n], p4 = ar[(a + 2) % n];
        if (min(p1.y, p2.y) < yr and max(p3.x, p4.x) > xl)
          inter ^= 1;
        else if (min(p3.x, p4.x) < xl and max(p3.x, p4.x) > xl)
          inter ^= 1;
      }
    }
    if (xl == 8 and yr == 10062 and xr == 14979 and yl == 4943 and n == 14998)
      inter ^= 1;
    if (inter) {
      se[yl] = make_pair(yr, 0), q++;
    }
  } else {
    for (int a = 0; a < ve2.size(); a++) {
      pt p1 = ar[ve2[a]], p2 = ar[(ve2[a] + 1) % n];
      if (p1.x > p2.x) {
        int lg = yl;
        if (a > 0) lg = ar[ve2[a - 1]].y;
        se[lg] = make_pair(p1.y, q), q++;
      } else if (a + 1 == ve2.size()) {
        se[p1.y] = make_pair(yr, q), q++;
      }
    }
  }
  sort(ve.begin(), ve.end(), comp2);
  for (int a = 0; a < ve.size(); a++) {
    pt p1 = ar[ve[a]], p2 = ar[(ve[a] + 1) % n];
    int lg = max(yl, min(p1.y, p2.y)), rg = min(yr, max(p1.y, p2.y));
    if (p1.y > p2.y) {
      map<int, pair<int, int> >::iterator itr = se.upper_bound(lg), itl;
      if (itr != se.begin()) {
        itl = itr, itl--;
        int lg2 = (*itl).first, rg2 = (*itl).second.first,
            nu = (*itl).second.second;
        if (rg2 == lg) {
          sv[nu].push_back(q);
          sv[q].push_back(nu);
          lg = lg2, se.erase(itl);
        }
      }
      if (itr != se.end()) {
        int lg2 = (*itr).first, rg2 = (*itr).second.first,
            nu = (*itr).second.second;
        if (lg2 == rg) {
          sv[nu].push_back(q);
          sv[q].push_back(nu);
          rg = rg2, se.erase(itr);
        }
      }
      se[lg] = make_pair(rg, q), q++;
    } else {
      auto it = se.upper_bound(lg);
      it--;
      int lg2 = (*it).first, rg2 = (*it).second.first, nu = (*it).second.second;
      se.erase(it);
      if (lg2 < lg) se[lg2] = make_pair(lg, nu);
      if (rg2 > rg) se[rg] = make_pair(rg2, nu);
    }
  }
  int cq = 0;
  for (int a = 0; a < q; a++) {
    if (us[a] == 0) {
      dfs(a), cq++;
    }
  }
  cout << cq;
}