#SGM0000009. Đàn kiến (Ant Colony)
Đàn kiến (Ant Colony)
Ant Colony
Source: Codeforces
Version: Phuoc Hung OJ Extended
There are ants in a row. Ant has strength . For a query segment , every pair of ants in the segment fights. Ant receives one point against ant if divides .
An ant is freed only if it scores a point in every fight it participates in, i.e. exactly points. All other ants are eaten.
For each query, print the number of ants that are eaten.
Input
The first line contains .
The second line contains .
The third line contains .
Each of the next lines contains .
Output
Print the number of eaten ants for every query.
Subtasks
- Subtask 1 — 20%: , .
- Subtask 2 — 30%: , .
- Subtask 3 — 50%: , .
Examples
Input
5
1 3 2 4 2
4
1 5
2 5
3 5
4 5
Output
4
4
1
1
Explanation
The sample follows the operations exactly; each printed line corresponds to a query that requires output.