🏡 index : github.com/captn3m0/codechef.git

---
{"category_name":"easy","problem_code":"FUZZYLIN","problem_name":"Fuzzy Linear Combinations","problemComponents":{"constraints":"","constraintsState":false,"subtasks":"","subtasksState":false,"inputFormat":"","inputFormatState":false,"outputFormat":"","outputFormatState":false,"sampleTestCases":{"0":{"id":1,"input":"2\n2 4\n3\n1\n2\n8","output":"0\n2\n3","explanation":"The sequence $(2, 4)$ has three contiguous subsequences: $(2)$, $(4)$ and $(2, 4)$. \n- In the first query, $1$ cannot be generated by any subsequence.\n- In the second query, $2$ is generated by subsequences $(2)$ and $(2, 4)$. For example, for the subsequence $(2, 4)$, we can choose $C_1 = 1$ and $C_2 = 0$.\n- In the third query, $8$ is generated by all three subsequences.","isDeleted":false}}},"video_editorial_url":"","languages_supported":{"0":"CPP14","1":"C","2":"JAVA","3":"PYTH 3.6","4":"PYTH","5":"PYP3","6":"CS2","7":"ADA","8":"PYPY","9":"TEXT","10":"PAS fpc","11":"NODEJS","12":"RUBY","13":"PHP","14":"GO","15":"HASK","16":"TCL","17":"PERL","18":"SCALA","19":"LUA","20":"kotlin","21":"BASH","22":"JS","23":"LISP sbcl","24":"rust","25":"PAS gpc","26":"BF","27":"CLOJ","28":"R","29":"D","30":"CAML","31":"FORT","32":"ASM","33":"swift","34":"FS","35":"WSPC","36":"LISP clisp","37":"SQL","38":"SCM guile","39":"PERL6","40":"ERL","41":"CLPS","42":"ICK","43":"NICE","44":"PRLG","45":"ICON","46":"COB","47":"SCM chicken","48":"PIKE","49":"SCM qobi","50":"ST","51":"NEM"},"max_timelimit":1,"source_sizelimit":50000,"problem_author":"hackslash_123","problem_tester":null,"date_added":"15-07-2019","tags":{"0":"anand20","1":"bezout","2":"greatest","3":"hackslash_123","4":"sept19","5":"sieve","6":"subarray"},"problem_difficulty_level":"Easy","best_tag":"Greatest Common Divisor","editorial_url":"https://discuss.codechef.com/problems/FUZZYLIN","time":{"view_start_date":1568626202,"submit_start_date":1568626202,"visible_start_date":1568626202,"end_date":1735669800},"is_direct_submittable":false,"problemDiscussURL":"https://discuss.codechef.com/search?q=FUZZYLIN","is_proctored":false,"visitedContests":{},"layout":"problem"}
---
### Read problem statements in [Hindi](https://www.codechef.com/download/translated/SEPT19/hindi/FUZZYLIN.pdf), [Bengali](https://www.codechef.com/download/translated/SEPT19/bengali/FUZZYLIN.pdf), [Mandarin Chinese](https://www.codechef.com/download/translated/SEPT19/mandarin/FUZZYLIN.pdf), [Russian](https://www.codechef.com/download/translated/SEPT19/russian/FUZZYLIN.pdf), and [Vietnamese](https://www.codechef.com/download/translated/SEPT19/vietnamese/FUZZYLIN.pdf) as well.

Chef recently took a course in linear algebra and learned about linear combinations of vectors. Therefore, in order to test his intelligence, Raj gave him a "fuzzy" problem to solve.

A sequence of integers $B_1, B_2, \ldots, B_M$ *generates* an integer $K$ if it is possible to find a sequence of integers $C_1, C_2, \ldots, C_M$ such that $C_1 \cdot B_1 + C_2 \cdot B_2 + \ldots + C_M \cdot B_M = K$.

In this problem, Chef has a sequence $A_1, A_2, \ldots, A_N$ and he should answer $Q$ queries. In each query, he is given an integer $K$; the answer to this query is the number of pairs $(l, r)$ such that $1 \le l \le r \le N$ and the subsequence $(A_l, A_{l+1}, \ldots, A_r)$ generates $K$.

Chef has no idea how to solve this problem ― can you help him find the answers to all queries?

### Input
- The first line of the input contains a single integer $N$.
- The second line contains $N$ space-separated integers $A_1, A_2, \ldots, A_N$.
- The third line contains a single integer $Q$.
- The following $Q$ lines describe queries. Each of these lines contains a single integer $K$.

### Output
For each query, print a single line containing one integer ― the number of contiguous subsequences that generate $K$.

### Constraints 
- $1 \le N, Q \le 10^5$
- $1 \le A_i \le 10^9$ for each valid $i$
- $1 \le K \le 10^6$

### Subtasks
**Subtask #1 (10 points):** $1 \le N \le 1,000$

**Subtask #2 (90 points):** original constraints

### Example Input
```
2
2 4
3
1
2
8
```

### Example Output
```
0
2
3
```

### Explanation
The sequence $(2, 4)$ has three contiguous subsequences: $(2)$, $(4)$ and $(2, 4)$. 
- In the first query, $1$ cannot be generated by any subsequence.
- In the second query, $2$ is generated by subsequences $(2)$ and $(2, 4)$. For example, for the subsequence $(2, 4)$, we can choose $C_1 = 1$ and $C_2 = 0$.
- In the third query, $8$ is generated by all three subsequences.

<aside style='background: #f8f8f8;padding: 10px 15px;'><div>All submissions for this problem are available.</div></aside>