Problem: Given a sequence of integers a1, ..., an and q queries x1, ..., xq on it. For each query xi you have to count the number of pairs (l, r) such that 1 ≤ l ≤ r ≤ n and gcd(al, al + 1, ..., ar) = xi.

<image> is a greatest common divisor of v1, v2, ..., vn, that is equal to a largest positive integer that divides all vi.

Input

The first line of the input contains integer n, (1 ≤ n ≤ 105), denoting the length of the sequence. The next line contains n space separated integers a1, ..., an, (1 ≤ ai ≤ 109).

The third line of the input contains integer q, (1 ≤ q ≤ 3 × 105), denoting the number of queries. Then follows q lines, each contain an integer xi, (1 ≤ xi ≤ 109).

Output

For each query print the result in a separate line.

Examples

Input

3
2 6 3
5
1
2
3
4
6


Output

1
2
2
0
1


Input

7
10 20 3 15 1000 60 16
10
1
2
3
4
5
6
10
20
60
1000


Output

14
0
2
2
2
0
2
2
1
1

Solution (in JAVA):

Solution:
import java.util.*;
import java.io.*;
public class MainClass
{
    public static void main(String[] args) throws IOException
    {
        Reader in = new Reader();
        StringBuilder stringBuilder = new StringBuilder();
        int n = in.nextInt();
        int[] A = new int[n];
        for (int i=0;i<n;i++)   A[i] = in.nextInt();
        HashMap<Integer, Long> results = new HashMap<>();
        HashMap<Integer, Long> divisors = new HashMap<>();
        HashMap<Integer, Long> nextDivisors = new HashMap<>();
        for (int i=0;i<n;i++)
        {
            nextDivisors.clear();
            for (int div: divisors.keySet())
            {
                int gg = gcd(div, A[i]);
                if (!nextDivisors.containsKey(gg))  nextDivisors.put(gg, divisors.get(div));
                else    nextDivisors.put(gg, nextDivisors.get(gg) + divisors.get(div));
            }
            if (!nextDivisors.containsKey(A[i]))    nextDivisors.put(A[i], 1L);
            else    nextDivisors.put(A[i], nextDivisors.get(A[i]) + 1);
            for (int div: nextDivisors.keySet())
            {
                if (!results.containsKey(div))
                    results.put(div, nextDivisors.get(div));
                else
                    results.put(div, nextDivisors.get(div) + results.get(div));
            }
            HashMap<Integer, Long> temp = (HashMap<Integer, Long>) nextDivisors.clone();
            nextDivisors = (HashMap<Integer, Long>) divisors.clone();
            divisors = temp;
        }
        int q = in.nextInt();
        while (q-- > 0)
        {
            int x = in.nextInt();
            if (results.containsKey(x))
                stringBuilder.append(results.get(x)).append("\n");
            else
                stringBuilder.append("0\n");
        }
        System.out.println(stringBuilder);
    }
    public static int gcd(int a, int b)
    {
        if (b == 0) return a;
        return gcd(b, a % b);
    }
}
class Reader
{
    final private int BUFFER_SIZE = 1 << 16;
    private DataInputStream din;
    private byte[] buffer;
    private int bufferPointer, bytesRead;

    public Reader()
    {
        din = new DataInputStream(System.in);
        buffer = new byte[BUFFER_SIZE];
        bufferPointer = bytesRead = 0;
    }

    public Reader(String file_name) throws IOException
    {
        din = new DataInputStream(new FileInputStream(file_name));
        buffer = new byte[BUFFER_SIZE];
        bufferPointer = bytesRead = 0;
    }

    public String readLine() throws IOException
    {
        byte[] buf = new byte[64]; // line length
        int cnt = 0, c;
        while ((c = read()) != -1)
        {
            if (c == '\n')
                break;
            buf[cnt++] = (byte) c;
        }
        return new String(buf, 0, cnt);
    }

    public int nextInt() throws IOException
    {
        int ret = 0;
        byte c = read();
        while (c <= ' ')
            c = read();
        boolean neg = (c == '-');
        if (neg)
            c = read();
        do
        {
            ret = ret * 10 + c - '0';
        }  while ((c = read()) >= '0' && c <= '9');

        if (neg)
            return -ret;
        return ret;
    }

    public long nextLong() throws IOException
    {
        long ret = 0;
        byte c = read();
        while (c <= ' ')
            c = read();
        boolean neg = (c == '-');
        if (neg)
            c = read();
        do {
            ret = ret * 10 + c - '0';
        }
        while ((c = read()) >= '0' && c <= '9');
        if (neg)
            return -ret;
        return ret;
    }

    public double nextDouble() throws IOException
    {
        double ret = 0, div = 1;
        byte c = read();
        while (c <= ' ')
            c = read();
        boolean neg = (c == '-');
        if (neg)
            c = read();

        do {
            ret = ret * 10 + c - '0';
        }
        while ((c = read()) >= '0' && c <= '9');

        if (c == '.')
        {
            while ((c = read()) >= '0' && c <= '9')
            {
                ret += (c - '0') / (div *= 10);
            }
        }

        if (neg)
            return -ret;
        return ret;
    }

    private void fillBuffer() throws IOException
    {
        bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
        if (bytesRead == -1)
            buffer[0] = -1;
    }

    private byte read() throws IOException
    {
        if (bufferPointer == bytesRead)
            fillBuffer();
        return buffer[bufferPointer++];
    }

    public void close() throws IOException
    {
        if (din == null)
            return;
        din.close();
    }
}