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.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.BufferedWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.util.TreeSet;
import java.util.TreeMap;
import java.util.Map;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        OutputWriter out = new OutputWriter(outputStream);
        TaskD solver = new TaskD();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskD {
        int gcd(int x, int y) {
            return (x == 0) ? y : (y == 0 ? x : gcd(y, x % y));
        }

        public void solve(int testNumber, InputReader in, OutputWriter out) {
            TreeMap<Integer, Long> freq = new TreeMap<>();
            TreeSet<Integer> queries = new TreeSet<>();
            int n = in.nextInt();
            int[] a = new int[n];
            for (int i = 0; i < n; i++) a[i] = in.nextInt();
            int q = in.nextInt();
            int[] x = new int[q];
            for (int i = 0; i < q; i++) {
                x[i] = in.nextInt();
                queries.add(x[i]);
            }
            RmqSparseTable table = new RmqSparseTable(a);
            for (int i = 0; i < n; i++) {
                int pos = i;
                while (pos < n) {
                    int lo = pos, hi = n - 1, curr_gcd = table._gcd(i, lo);
                    ;
                    while (lo < hi) {
                        int mid = (lo + hi + 1) >> 1;
                        if (table._gcd(i, mid) == curr_gcd) {
                            lo = mid;
                        } else {
                            hi = mid - 1;
                        }
                    }

                    if (queries.contains(curr_gcd)) {
                        freq.put(curr_gcd, freq.getOrDefault(curr_gcd, 0L) + hi - pos + 1);
                    }
                    pos = hi + 1;
                }
            }

            for (int i = 0; i < q; i++) out.println(freq.getOrDefault(x[i], 0L));
        }

        public class RmqSparseTable {
            int[] logTable;
            int[][] rmq;
            int[] a;

            public RmqSparseTable(int[] a) {
                this.a = a;
                int n = a.length;

                logTable = new int[n + 1];
                for (int i = 2; i <= n; i++)
                    logTable[i] = logTable[i >> 1] + 1;

                rmq = new int[logTable[n] + 1][n];

                for (int i = 0; i < n; ++i)
                    rmq[0][i] = i;

                for (int i = n - 1; i >= 0; i--) {
                    rmq[0][i] = a[i];
                    for (int j = 1; i + (1 << j) - 1 < n; j++) {
                        rmq[j][i] = gcd(rmq[j - 1][i], rmq[j - 1][i + (1 << (j - 1))]);
                    }
                }
            }

            public int _gcd(int i, int j) {
                int k = logTable[j - i];
                int x = rmq[k][i];
                int y = rmq[k][j - (1 << k) + 1];
                return gcd(x, y);
            }

        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private InputReader.SpaceCharFilter filter;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1) {
                throw new InputMismatchException();
            }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }

        public int nextInt() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public boolean isSpaceChar(int c) {
            if (filter != null) {
                return filter.isSpaceChar(c);
            }
            return isWhitespace(c);
        }

        public static boolean isWhitespace(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }

    static class OutputWriter {
        private final PrintWriter writer;

        public OutputWriter(OutputStream outputStream) {
            writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
        }

        public OutputWriter(Writer writer) {
            this.writer = new PrintWriter(writer);
        }

        public void close() {
            writer.close();
        }

        public void println(long i) {
            writer.println(i);
        }

    }
}