Hide

Problem C
All Pair Sums

Accepted submissions to this problem will be granted a score of 15
Languages en is

You are given two multisets of integers, A and B. Then you are given queries containing a number x and are asked to find the number of ways to write x as a sum of two numbers aA and bB.

Input

The first line of input contains two positive integers n,m, the number of values in each multiset. The next two lines then contain the integers in each multiset. Each value x in the multisets satisfies 105x105. Next there is a line with a positive integer q105, the number of queries. Next there are q lines, each containing an integer x satisfying 109x109.

Output

For each query x you should print the number of ways to pick aA and bB such that x=a+b. Print each number on its own line.

Sample Input 1 Sample Output 1
3 4
1 2 3
4 5 6 7
3
5
7
9
1
3
2
Hide

Please log in to submit a solution to this problem

Log in