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:
// This is another solution see the previous solution too
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.util.TreeMap;
 
 
public class E {
 
	public static void main(String[] args) throws IOException 
	{
		Scanner sc = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);
		int n = sc.nextInt(), a[] = new int[n];
		for(int i = 0; i < n; ++i)
			a[i] = sc.nextInt();
		TreeMap<Integer, Long> map = new TreeMap<Integer, Long>();
		SparseTable st = new SparseTable(a);
 
		for(int i = 0; i < n; ++i)
		{
			int j = i;
			while(j < n)
			{
				int lst = -1, lo = j, hi = n - 1, g = st.query(i, j);
				while(lo <= hi)
				{
					int mid = lo + hi >> 1;
					if(st.query(i, mid) == g)
					{
						lst = mid;
						lo = mid + 1;
					}
					else
						hi = mid - 1;					
				}
				Long f = map.get(g);
				if(f == null)
					f = 0l;
				map.put(g, f + lst - j + 1);
				j = lst + 1;
			}
		}
		int q = sc.nextInt();
		StringBuilder sb = new StringBuilder();
		while(q-->0)
		{
			Long ans = map.get(sc.nextInt());
			if(ans == null)
				ans = 0l;
			sb.append(ans + "\n");
		}
		out.print(sb);
		out.flush();
		out.close();
	}
	
	
	static int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
	
	static int[] log;
	
	static void preLog(int N)
	{
		log = new int[N + 1];
		int k = 0;
		for(int i = 1; i <= N; ++i)
		{
			if(1<<k+1 <= i)
				++k;
			log[i] = k;
		}
	}
	
	static class SparseTable
	{
		int[][] ST;
		
		SparseTable(int[] A)
		{
			int n = A.length;
			preLog(n);
			int k = 0; while(1<<k+1 <= n) ++k;;
			ST = new int[k + 1][n];
			for(int i = 0; i < n; ++i)
				ST[0][i] = A[i];
			for(int j = 1; j <= k; ++j)
				for(int i = 0; i + (1<<j) <= n; ++i)
					ST[j][i] = gcd(ST[j-1][i], ST[j-1][i + (1<<j-1)]);
		}
		
		int query(int l, int r)
		{
			int k = log[r - l + 1];
			return gcd(ST[k][l], ST[k][r - (1<<k) + 1]);
		}
	}
	
	static class Scanner 
	{
		StringTokenizer st;
		BufferedReader br;
 
		public Scanner(InputStream s){	br = new BufferedReader(new InputStreamReader(s));}
 
		public Scanner(FileReader r){	br = new BufferedReader(r);}
 
		public String next() throws IOException 
		{
			while (st == null || !st.hasMoreTokens()) 
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}
 
		public int nextInt() throws IOException {return Integer.parseInt(next());}
 
		public long nextLong() throws IOException {return Long.parseLong(next());}
 
		public String nextLine() throws IOException {return br.readLine();}
 
		public double nextDouble() throws IOException { return Double.parseDouble(next()); }
 
		public boolean ready() throws IOException {return br.ready();}
 
 
	}
}