QOJ.ac

QOJ

Time Limit: 2 s Memory Limit: 1024 MB Total points: 100

#15513. Waterfall

الإحصائيات

Alexander likes water. Therefore, it’s no surprise that he is fond of rushing water. This might explain why he wants to create his own waterfall. Just imagine, water cascading endlessly!

He has found a cliff face that he believes will make the perfect waterfall after he adds some water. The cliff face can be modeled as an $R \times C$ grid, where $N$ cells have an outcropping cliff. Alexander plans to pour water from above so that it flows down in $K$ columns.

The water spreads in the grid according to the following rules: if the cell below the water is empty, it spreads there. If there is a cliff in the way, it instead spreads to the right and left. If there is a cliff in the way to the right or left, it does not spread in that direction. This also applies to the water being poured from above, i.e., if water is poured into column $i$ and the top row has a cliff in column $i$, it is as if water is also being poured from above in columns $i - 1$ and $i + 1$, provided those columns are within the grid.

However, Alexander does not want to cause a flood because then all the water will stand still in the end. Water that stands still is, of course, less exciting than rushing water. Therefore, he wants your help to write a program that calculates how many columns have water in them in the bottom row of the cliff.

problem_15513_1.png problem_15513_2.png

Figure 1: An illustration of the flow in sample 1 and 2. The red frame marks the end of the cliff face.

Input

The first line contains two integers $R, C$ ($1 \le R, C \le 10^9$), the number of rows and columns that make up the mountain.

The second line contains two integers $K, N$ ($1 \le K, N \le 10^5$), the number of columns with water and the number of cliffs protruding from the mountain.

Following this are $K$ lines, where the $i$-th line contains a number $V_i$ ($0 \le V_i \le C-1$), indicating that water flows down along column $V_i$ from above the grid. It is guaranteed that all $V_i$ are unique.

Afterward, there are $N$ lines where each line $i$ contains two integers $A_i$ ($1 \le A_i \le R-1$) and $B_i$ ($0 \le B_i \le C-1$), representing the row and column where the $i$-th cliff is located. These positions are also unique.

Output

Print an integer: the number of columns that contain water in the bottom row of the grid.

Examples

Input

8 6
3 4
1
4
5
1 3
2 2
5 1
5 5

Output

3

Input

8 6
1 8
3
2 1
1 2
2 3
5 2
5 3
5 4
5 5
6 5

Output

1

Input

5 4
1 3
3
1 1
2 2
3 3

Output

1

Scoring

Your solution will be tested on a set of test groups, each worth a number of points. Each test group contains a set of test cases. To get the points for a test group you need to solve all test cases in the test group.

Group Points Constraints
$1$ $20$ $R \cdot C \le 1000$
$2$ $30$ Cliffs can’t touch each other diagonally, horizontally or vertically.
$3$ $20$ Cliffs can’t touch each other diagonally.
$4$ $30$ No additional constraints.
About Issues

We understand that our problem archive is not perfect. If you find any issues with the problem, including the statement, scoring configuration, time/memory limits, test cases, etc.

You may use this form to submit an issue regarding the problem. A problem moderator will review your issue and proceed it properly.

STOP! Before you submit an issue, please READ the following guidelines:

  1. This is not a place to publish a discussion, editorial, or requests to debug your code. Your issue will only be visible by you and problem moderators. Other users will not be able to view or reply your issues.
  2. Do not submit duplicated issues. If you have already submitted one, please wait for an moderator to review it. Submitting multiple issues will not speed up the review process and might cause your account to be banned.
  3. Issues must be filed in English or Chinese only.
  4. Be sure your issue is related to this problem. If you need to submit an issue regarding another problem, contest, category, etc., you should submit it to the corresponding page.

Active Issues 0

No issues in this category.

Closed/Resolved Issues 0

No issues in this category.