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.*;
/*NO RESPECT*/

public class Main implements Runnable {
static boolean showTime = false;

        class Query implements Comparable<Query>{
            int v, id;
            Query(int v, int id){
                this.v = v;
                this.id = id;
            }
            public int compareTo(Query b){
                return v - b.v;
            }
        }
        
        private int gcd(int m, int n){
            if(n == 0)
                return m;
            else 
                return gcd(n, m % n);
        }
        
        private void add(int gcd, int len){
            int l = -1, r = q.length;
            while(r - l > 1){
                int m = (l + r) >> 1;
                if(q[m].v >= gcd){
                    r = m;
                }
                else{
                    l = m;
                }
                
            }
            
            if(r == q.length || q[r].v != gcd)
                return;
            sum[r] += len;
            
            
            l = 0;
            r = q.length;
            while(r - l > 1){
                int m = (l + r) >> 1;
                if(q[m].v <= gcd){
                    l = m;
                }
                else{
                    r = m;
                }
                
            }
            
            sum[l + 1] -= len;
        }
        
        
        
        Query[] q;
        long[] sum;
	public void solve() throws IOException {
		int n = nextInt();

                final int MAX = 20;
                int[][] gcd = new int[MAX][n]; //SPARSE TABLE
                for(int i = 0; i < n; i++){
                    gcd[0][i] = nextInt();
                }
                
                for(int i = 1; i < MAX; i++){
                    for(int j = 0; j < n; j++){
                        int next = j + (1 << (i-1));
                        if(next >= n)
                            gcd[i][j] = gcd[i-1][j];
                        else
                            gcd[i][j] = gcd(gcd[i-1][j], gcd[i-1][next]);
                    }
                }
                
                int Q = nextInt();
                q = new Query[Q];
                for(int i = 0; i < Q; i++){
                    q[i] = new Query(nextInt(), i);
                }
                Arrays.sort(q);
                sum = new long[Q + 1];
                
                for(int start = 0; start < n; start++){
                    int from = start;
                    int curGcd = gcd[0][start];
                    while(true){
                        int len = 0;
                        for(int i = MAX - 1; i >= 0; i--){ //find the furthest point where gcd is curGCD
                            if(from != n && gcd[i][from] % curGcd == 0){
                                int add = Math.min(1 << i, n - from);
                                len += add;
                                from += add;
                            }
                        }
                        
                        add(curGcd, len); //update in our results from index l....r 
                        if(from == n)
                            break;
                        curGcd = gcd(curGcd, gcd[0][from]);
                    }
                }
                
                long[] answer = new long[Q];
                long temp = 0;
                for(int i = 0; i < Q; i++){
                    temp += sum[i];
                    answer[q[i].id] = temp;
                }
                
                for(int i = 0; i < Q; i++){
                    out.println(answer[i]);
                }
	}

	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	//-----------------------------------------------------------
	public static void main(String[] args) {
		new Main().run();
	}

        public void debug(Object... arr){
            System.out.println(Arrays.deepToString(arr));
        }

        public void print1Int(int[] a){
                for(int i = 0; i < a.length; i++)
                        System.out.print(a[i] + " ");
                System.out.println();
        }
        
        public void print2Int(int[][] a){
                for(int i = 0; i < a.length; i++){
                        for(int j = 0; j < a[0].length; j++){
                                System.out.print(a[i][j] + " ");
                        }
                        System.out.println();
                }
        }
        
	public void run() {
		try {
			in = new BufferedReader(new InputStreamReader(System.in));
                        out = new PrintWriter(System.out);
			tok = null;
			long start = System.currentTimeMillis();
			solve();
                        long end = System.currentTimeMillis();
                        if(showTime)System.err.println( (end - start) / 1000.0);
			in.close();
                        out.close();
		} catch (IOException e) {
			System.exit(0);
		}
	}

	public String nextToken() throws IOException {
		while (tok == null || !tok.hasMoreTokens()) {
			tok = new StringTokenizer(in.readLine());
		}
		return tok.nextToken();
	}

	public int nextInt() throws IOException {
		return Integer.parseInt(nextToken());
	}

	public long nextLong() throws IOException {
		return Long.parseLong(nextToken());
	}

	public double nextDouble() throws IOException {
		return Double.parseDouble(nextToken());
	}
        PrintWriter out;
	BufferedReader in;
	StringTokenizer tok;
}