Under construction

Still being built. Things may change

Difference

Time limit2sMemory limit1024 MB

Summary
Given two sequences A and B and an integer K, count the pairs (p, q) where A_p + K equals B_q.
Level

Easy1 of 10

Topics
Array, Hash map
Solved
No attempts yet

Problem

You are given an integer KK, an integer sequence A=(A1,A2,…,AN)A=(A_1,A_2,\ldots,A_N) of length NN, and an integer sequence B=(B1,B2,…,BM)B=(B_1,B_2,\ldots,B_M) of length MM.

Count the pairs of integers (p,q)(p,q) that satisfy all of the following conditions.

  • 1≤p≤N1 \le p \le N.
  • 1≤q≤M1 \le q \le M.
  • Ap+K=BqA_p + K = B_q.

Input

The input is given in the following format.

K
N
A1   A2   …   AN
M
B1   B2 …   BM

Output

Print the number of pairs (p,q)(p,q) that satisfy all the conditions.

Print only the answer. Do not print any prompt or other text.

Constraints

  • 1≤K≤1001 \le K \le 100.
  • 1≤N≤1001 \le N \le 100.
  • 1≤M≤1001 \le M \le 100.
  • 1≤Ai≤1001 \le A_i \le 100 (1≤i≤N1 \le i \le N).
  • 1≤Bj≤1001 \le B_j \le 100 (1≤j≤M1 \le j \le M).
  • All input values are integers.

Examples4

  1. Example 1

    Input
    1
    4
    1 8 6 8
    3
    7 9 4
    
    Expected output
    3
    
  2. Example 2

    Input
    66
    4
    31 41 59 26
    5
    29 97 92 45 8
    
    Expected output
    2
    
  3. Example 3

    Input
    99
    5
    1 1 1 1 1
    6
    100 100 100 100 100 100
    
    Expected output
    30
    
  4. Example 4

    Input
    100
    1
    11
    1
    18
    
    Expected output
    0