{"raw_statement":[{"iden":"statement","content":"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.\n\nAlso, 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.\n\n<center>![image](https://espresso.codeforces.com/f1e813469b662d85fddcd0e754608f215d2f511b.png) Blue color represents the border of a polygon, red color is the Petya's window. The answer in this case is 2.</center>Determine the number of black connected areas of Petya's polygon, which can be seen through the rectangular window."},{"iden":"input","content":"The first line contain four integers $x_1, y_1, x_2, y_2$ ($x_1 &lt; x_2$, $y_2 &lt; y_1$) — the coordinates of top-left and bottom-right corners of the rectangular window.\n\nThe second line contains a single integer $n$ ($4 \\le n \\le 15\\,000$) — the number of vertices in Petya's polygon.\n\nEach 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.\n\nAll coordinates of the rectangular window and all coordinates of the vertices of the polygon are non-negative and do not exceed $15\\,000$."},{"iden":"output","content":"Print the number of black connected areas of Petya's polygon, which can be seen through the rectangular window."},{"iden":"example","content":"Input\n\n5 7 16 3\n16\n0 0\n18 0\n18 6\n16 6\n16 1\n10 1\n10 4\n7 4\n7 2\n2 2\n2 6\n12 6\n12 12\n10 12\n10 8\n0 8\n\nOutput\n\n2"},{"iden":"note","content":"The example corresponds to the picture above."}],"translated_statement":[{"iden":"statement","content":"Petya 有一个由 $n$ 个顶点组成的多边形。Petya 的多边形的所有边均平行于坐标轴，且每两条相邻边互相垂直。保证该多边形是简单的，即不存在自相交或自接触。Petya 将多边形的所有内部区域（不包括边界）涂成了黑色。\n\n此外，Petya 有一个矩形窗口，由其坐标定义，他通过该窗口观察多边形。矩形窗口不可移动，其边平行于坐标轴。\n\n请确定通过矩形窗口可以看到的 Petya 多边形中多少个黑色连通区域。\n\n第一行包含四个整数 $x_1, y_1, x_2, y_2$（$x_1 < x_2$，$y_2 < y_1$）——矩形窗口的左上角和右下角坐标。\n\n第二行包含一个整数 $n$（$4 lt.eq n lt.eq 15 thin 000$）——Petya 多边形的顶点数。\n\n接下来的 $n$ 行每行包含两个整数，表示按逆时针顺序给出的 Petya 多边形的顶点坐标。保证给出的多边形满足题目所述条件。\n\n矩形窗口和多边形所有顶点的坐标均为非负数，且不超过 $15 thin 000$。\n\n请输出可以通过矩形窗口看到的 Petya 多边形中黑色连通区域的数量。\n\n该示例对应于上图。"},{"iden":"input","content":"第一行包含四个整数 $x_1, y_1, x_2, y_2$（$x_1 < x_2$，$y_2 < y_1$）——矩形窗口的左上角和右下角坐标。第二行包含一个整数 $n$（$4 lt.eq n lt.eq 15 thin 000$）——Petya 多边形的顶点数。接下来的 $n$ 行每行包含两个整数，表示按逆时针顺序给出的 Petya 多边形的顶点坐标。保证给出的多边形满足题目所述条件。矩形窗口和多边形所有顶点的坐标均为非负数，且不超过 $15 thin 000$。"},{"iden":"output","content":"请输出可以通过矩形窗口看到的 Petya 多边形中黑色连通区域的数量。"},{"iden":"note","content":"该示例对应于上图。"}],"sample_group":[],"show_order":[],"formal_statement":"**Definitions**  \nLet $ R = [x_1, x_2] \\times [y_2, y_1] \\subset \\mathbb{R}^2 $ be the rectangular window, with $ x_1 < x_2 $, $ y_2 < y_1 $.  \nLet $ P \\subset \\mathbb{R}^2 $ be a simple polygon with $ n $ vertices, given in counterclockwise order, such that:  \n- All edges of $ P $ are axis-aligned (horizontal or vertical).  \n- Consecutive edges are perpendicular (i.e., $ P $ is a rectilinear polygon).  \n- The interior of $ P $ is colored black.  \n\nLet $ \\text{int}(P) $ denote the open interior of $ P $ (excluding boundary).  \n\nLet $ C_1, C_2, \\dots, C_m $ be the connected components of $ \\text{int}(P) $.\n\n**Constraints**  \n1. $ 4 \\le n \\le 15{,}000 $  \n2. All vertex coordinates and window coordinates are integers in $ [0, 15{,}000] $  \n3. $ R $ is axis-aligned and fixed.  \n\n**Objective**  \nCompute the number of connected components $ C_i $ of $ \\text{int}(P) $ such that $ C_i \\cap R \\neq \\emptyset $.  \n\nThat is, compute:  \n$$\n\\left| \\left\\{ C_i \\mid C_i \\text{ is a connected component of } \\text{int}(P) \\text{ and } C_i \\cap R \\neq \\emptyset \\right\\} \\right|\n$$","simple_statement":null,"has_page_source":false}