QOJ.ac

QOJ

Time Limit: 2 s Memory Limit: 1024 MB

#23942. Difference

Statistics

You are given an integer $K$, an integer sequence $A=(A_1,A_2,\ldots,A_N)$ of length $N$, and an integer sequence $B=(B_1,B_2,\ldots,B_M)$ of length $M$.

Find the number of pairs of $2$ integers $(p,q)$ that satisfy all of the following conditions:

  • $1 \le p \le N$.
  • $1 \le q \le M$.
  • $A_p + K = B_q$.

Input

The input is given in the following format:

$$ \begin{aligned} &K \\ &N \\ &A_1 \ A_2 \ \cdots \ A_N \\ &M \\ &B_1 \ B_2 \ \cdots \ B_M \end{aligned} $$

Output

Output the number of pairs of $2$ integers $(p,q)$ that satisfy all the conditions.

Do not output anything other than the answer. (Do not output sentences prompting for input, etc.)

For the answer format, you may refer to the practice problems and their sample solutions.

Constraints

  • $1 \le K \le 100$.
  • $1 \le N \le 100$.
  • $1 \le M \le 100$.
  • $1 \le A_i \le 100$ ($1 \le i \le N$).
  • $1 \le B_j \le 100$ ($1 \le j \le M$).
  • All input values are integers.

Examples

Input 1

1
4
1 8 6 8
3
7 9 4

Output 1

3

Note 1

  • Since $A_2 = 8, B_2 = 9$ and $A_2 + 1 = B_2$ holds, the pair of integers $(2,2)$ satisfies the conditions.
  • Since $A_3 = 6, B_1 = 7$ and $A_3 + 1 = B_1$ holds, the pair of integers $(3,1)$ satisfies the conditions.
  • Since $A_4 = 8, B_2 = 9$ and $A_4 + 1 = B_2$ holds, the pair of integers $(4,2)$ satisfies the conditions.

There are $3$ pairs of integers that satisfy the conditions: $(2,2),(3,1),(4,2)$. Therefore, output $3$.

Input 2

66
4
31 41 59 26
5
29 97 92 45 8

Output 2

2

Note 2

  • Since $A_1 = 31, B_2 = 97$ and $A_1 + 66 = B_2$ holds, the pair of integers $(1,2)$ satisfies the conditions.
  • Since $A_4 = 26, B_3 = 92$ and $A_4 + 66 = B_3$ holds, the pair of integers $(4,3)$ satisfies the conditions.

There are $2$ pairs of integers that satisfy the conditions: $(1,2),(4,3)$. Therefore, output $2$.

Input 3

99
5
1 1 1 1 1
6
100 100 100 100 100 100

Output 3

30

Note 3

  • There are $30$ pairs of integers that satisfy the conditions. Therefore, output $30$.

Input 4

100
1
11
1
18

Output 4

0

Note 4

  • There are no pairs of integers that satisfy the conditions. Therefore, output $0$.

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.