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 double eps = 1e-9;
int X[16000][2];
int L[2][2];
int main() {
  for (int i = (0); i < (2); i++)
    for (int j = (0); j < (2); j++) cin >> L[i][j];
  int N;
  cin >> N;
  for (int i = (0); i < (N); i++)
    for (int j = (0); j < (2); j++) cin >> X[i][j];
  swap(L[0][1], L[1][1]);
  for (int i = (0); i < (N); i++)
    for (int j = (0); j < (2); j++)
      X[i][j] = max(min(X[i][j], L[1][j]), L[0][j]);
  vector<pair<int, int> > actions;
  bool allinside = true;
  for (int i = (0); i < (N); i++)
    for (int j = (0); j < (2); j++)
      for (int k = (0); k < (2); k++)
        if (X[i][j] == L[k][j]) allinside = false;
  if (allinside) {
    cout << 1 << endl;
    return 0;
  }
  map<int, int> adj;
  for (int i = (0); i < (N); i++) {
    int ii = (i + 1) % N;
    bool edgetravel = false;
    for (int k = (0); k < (2); k++)
      for (int j = (0); j < (2); j++)
        if (X[i][k] == L[j][k] && X[ii][k] == L[j][k]) edgetravel = true;
    if (edgetravel) continue;
    allinside = true;
    for (int k = (0); k < (2); k++)
      for (int j = (0); j < (2); j++)
        if (X[i][k] == L[j][k] || X[ii][k] == L[j][k]) allinside = false;
    int L0 = 0;
    pair<int, int> a1(-1, -1);
    pair<int, int> a2(-1, -1);
    if (X[i][1] == L[0][1]) {
      a1 = (make_pair(L0 + X[i][0] - L[0][0], 1));
    }
    if (X[ii][1] == L[0][1]) {
      a2 = (make_pair(L0 + X[ii][0] - L[0][0], 0));
    }
    L0 += L[1][0] - L[0][0];
    if (X[i][0] == L[1][0]) {
      a1 = (make_pair(L0 + X[i][1] - L[0][1], 1));
    }
    if (X[ii][0] == L[1][0]) {
      a2 = (make_pair(L0 + X[ii][1] - L[0][1], 0));
    }
    L0 += L[1][1] - L[0][1];
    if (X[i][1] == L[1][1]) {
      a1 = (make_pair(L0 - X[i][0] + L[1][0], 1));
    }
    if (X[ii][1] == L[1][1]) {
      a2 = (make_pair(L0 - X[ii][0] + L[1][0], 0));
    }
    L0 += L[1][0] - L[0][0];
    if (X[i][0] == L[0][0]) {
      a1 = (make_pair(L0 - X[i][1] + L[1][1], 1));
    }
    if (X[ii][0] == L[0][0]) {
      a2 = (make_pair(L0 - X[ii][1] + L[1][1], 0));
    }
    if (a1.first != -1) actions.push_back(a1);
    if (a2.first != -1) actions.push_back(a2);
  }
  int last = -1;
  for (auto it : actions) {
    if (it.second)
      last = it.first;
    else
      last = -1;
  }
  for (auto it : actions) {
    if (it.second) {
      assert(last == -1);
      last = it.first;
    } else {
      adj[last] = it.first;
      last = -1;
    }
  }
  sort((actions).begin(), (actions).end());
  last = -1;
  for (auto it : actions) {
    if (!it.second)
      last = it.first;
    else
      last = -1;
  }
  for (auto it : actions) {
    if (!it.second) {
      assert(last == -1);
      last = it.first;
    } else {
      adj[last] = it.first;
      last = -1;
    }
  }
  int res = 0;
  unordered_set<int> vis;
  for (auto it : actions) {
    int p = it.first;
    if (vis.find(p) != vis.end()) continue;
    ++res;
    while (vis.find(p) == vis.end()) {
      vis.insert(p);
      assert(adj.find(p) != adj.end());
      p = adj[p];
    }
  }
  if (res == 0) {
    long long A = 0;
    for (int i = (1); i < (N + 1); i++) {
      long long d = (long long)X[i - 1][0] * X[i % N][1] -
                    (long long)X[i % N][0] * X[i - 1][1];
      A += d;
    }
    if (A) res = 1;
  }
  cout << res << endl;
  return 0;
}