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.*;
import java.util.*;

public class Main {
    public static void main(String[] args){
        InputStream  inputstream;
        OutputStream outputstream;
        inputstream = System.in;
        outputstream = System.out;
        InputReader in = new InputReader(inputstream);
        PrintWriter out = new PrintWriter(outputstream);
        Task solver = new Task();
        solver.solve(in,out);
        out.close();
    }

    static class Task{

        final static int lg = 20;
        int n;
        int[] a;
        int[] log;
        int[][] sp;
        TreeMap <Integer,Long> ans = new TreeMap<Integer,Long>();

        public void solve(InputReader in,PrintWriter out){
            n = in.nextInt();
            a = new int[n + 2];
            sp = new int[n + 2][lg + 2];
            log = new int[n + 2];
            for(int i = 1; i <= n;++i){
                a[i] = in.nextInt();
                sp[i][0] = a[i];
            }
            for(int i = 2;i <= n;++i){
                log[i] = log[i >> 1] + 1;
            }
            for(int j = 1;j <= lg;++j){
                for(int i = 1;i + (1 << j) - 1 <= n;++i){
                    sp[i][j] = gcd(sp[i][j - 1],sp[i + (1 << (j - 1))][j - 1]);
                }
            }
            for(int i = 1;i <= n;++i){
                for(int j = i;j <= n;++j){
                    int cur = getGcd(i,j);
                    int l = j,r = n;
                    int pos = j;
                    for(int mid = (l + r) >> 1;l <= r;mid = (l + r) >> 1){
                        if(getGcd(i,mid) == cur){
                            l = mid + 1;
                            pos = mid;
                        } else {
                            r = mid - 1;
                        }
                    }
                    long val = 0;
                    if(ans.containsKey(cur)){
                        val = ans.get(cur);
                        ans.remove(cur);
                    }
                    ans.put(cur,val + (pos - j + 1));
                    j = pos;
                }
            }
            int q;
            q = in.nextInt();
            for(;q > 0;--q){
                int x;
                x = in.nextInt();
                if(ans.containsKey(x)){
                    out.println(ans.get(x));
                } else {
                    out.println(0);
                }
            }
        }

        int getGcd(int l,int r){
            int x = log[r - l + 1];
            return gcd(sp[l][x],sp[r - (1 << x) + 1][x]);
        }

        int gcd(int u,int v){
            if(v == 0){
                return u;
            }
            return gcd(v,u % v);
        }
    }

    static class InputReader{
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream){
            reader = new BufferedReader(new InputStreamReader(stream));
            tokenizer = null;
        }

        public String next(){
            while(tokenizer == null || !tokenizer.hasMoreTokens()){
                try{
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e){
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt(){
            return Integer.parseInt(next());
        }

        public long nextLong(){
            return Long.parseLong(next());
        }

        public  double nextDouble(){
            return Double.parseDouble(next());
        }

        public String nextLine(){
            String ret_str = "";
            try {
                ret_str = reader.readLine();
            } catch (IOException e){
                e.printStackTrace();
            }
            return ret_str;
        }
    }
}