Problem C
All Pair Sums
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 $a \in A$ and $b \in B$.
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 $-10^5 \leq x \leq 10^5$. Next there is a line with a positive integer $q \leq 10^5$, the number of queries. Next there are $q$ lines, each containing an integer $x$ satisfying $-10^9 \leq x \leq 10^9$.
Output
For each query $x$ you should print the number of ways to pick $a \in A$ and $b \in B$ 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 |