Hide

Problem J
Freebies Distribution

It’s hackathon season - finally time for Samuele to shine, and show all of his friends that he still has what it takes to grab some freebies.

/problems/itacpc22.freebiesdistribution/file/statement/en/img-0001.jpg
In fact, Samuele is not there to win, or to even try winning: he is always looking for new hackathons to join, especially when they come with SPA benefits. This time, there’s no SPA, but there’s $M$ different booths that will soon start handing out freebies. The hackathon is taking place in a rectangular grid. The booths are all positioned on the first row, and the $i-$th one is placed at coordinate $(0, B_ i)$.

Samuele knows the location of each of the other $N$ contestants, the $i$-th one being in coordinate $(R_ i, C_ i)$, while Samuele’s location is coordinate $(X, Y)$. There can be multiple contestants in the same coordinate.

Once the freebies distribution is announced, Samuele knows that each contestant will immediately move to the closest booth, choosing the leftmost one in case of a tie. Moving in the grid can only happen horizontally or vertically, and it takes one second to move by one in either direction.

Given this information, Samuele wants to optimize his strategy, maximing his chance of being able to choose the best available freebie: he will go to the booth that minimizes the amount of people getting there before him. If he gets at the booth at the same time as another contestant, his kindness will prevail and he will let them choose first.

Help him by computing the minimum amount of people that will reach the chosen booth before or at the same time as him.

Input

The first line contains one integer $M$, the number of booths.

The second line contains $M$ integers $B_ i$, each being the column coordinate of the $i$-th booth.

The third line contains two integers $X$ and $Y$, respectively the row and column of Samuele’s location.

The fourth line contains one integer $N$, the number of other contestants.

The next $N$ lines contain two integers $R_ i$ and $C_ i$, respectively the row and column of the $i$-th contestant.

Output

You need to write a single line containing a single integer: the minimum number of contestant that will make it to the booth at least as early as Samuele.

Constraints

  • $1 \le N \le 10^{6}$.

  • $1 \le M \le 10^{6}$.

  • $0 \le B_ i < 10^{9}$, for all $i$ in $[0, M-1]$.

  • All values $B_ i$ are distinct.

  • $0 \le R_ i, C_ i, X, Y < 10^{9}$, for all $i$ in $[0, N-1]$.

Example

In the first example below, there’s only one person that would get to the booth in $(0, 3)$ before Samuele.

/problems/itacpc22.freebiesdistribution/file/statement/en/img-0002.jpg
Sample Input 1 Sample Output 1
3
7 3 0
4 0
5
3 1
4 8
1 0
2 3
3 6
1

Please log in to submit a solution to this problem

Log in