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  gym{
	static int gcd(int a,int b) {
		if(b==0)return a;
		return gcd(b,a%b);
	}
	static int log=20;
	static int gcdRange(int l,int r,int[][]gcds,int[] logx) {
		int len=r-l+1;
		int loglen=logx[len];
		int firstR=gcds[l][loglen];
		int secR=gcds[r-(1<<loglen)+1][loglen];
		return gcd(firstR,secR);
	}
	public static void main(String[] args) throws Exception{
		MScanner sc=new MScanner(System.in);
		PrintWriter pw=new PrintWriter(System.out);
		int n=sc.nextInt();
		int[]in=sc.takearr(n);
		int[][]gcds=new int[n][log];
		int[]logx=new int[n+1];
		logx[1]=0;
		for(int i=2;i<=n;i++) {
			logx[i]=logx[i/2]+1;
		}
		for(int i=0;i<n;i++)gcds[i][0]=in[i];
		for(int l=1;l<log;l++) {
			for(int i=0;i+(1<<l)-1<n;i++) {
				gcds[i][l]=gcd(gcds[i][l-1], gcds[i+(1<<(l-1))][l-1]);
			}
		}
		HashMap<Integer, Long>map=new HashMap<Integer, Long>();
		for(int i=0;i<n;i++) {
			int gcd=in[i];
			int start=i;
			while(true) {
				int lo=start,hi=n-1;
				int last=-1;
				while(lo<=hi) {
					int mid=(lo+hi)>>1;
					if(gcdRange(i, mid, gcds, logx)==gcd) {
						last=mid;
						lo=mid+1;
					}
					else {
						hi=mid-1;
					}
				}
				if(last!=-1)
					map.put(gcd, map.getOrDefault(gcd, 0l)+last-start+1);
				else {
					last=start;					
				}
				//System.out.println(map);
				last++;
				if(last==n) {
					break;
				}
				gcd=gcdRange(i, last, gcds, logx);
				start=last;
			}
		}
		int q=sc.nextInt();
		while(q-->0) {
			pw.println(map.getOrDefault(sc.nextInt(), 0l));
		}
		pw.flush();
	}
	static class MScanner {
		StringTokenizer st;
		BufferedReader br;
		public MScanner(InputStream system) {
			br = new BufferedReader(new InputStreamReader(system));
		}
 
		public MScanner(String file) throws Exception {
			br = new BufferedReader(new FileReader(file));
		}
 
		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}
		public int[] takearr(int n) throws IOException {
	        int[]in=new int[n];for(int i=0;i<n;i++)in[i]=nextInt();
	        return in;
		}
		public long[] takearrl(int n) throws IOException {
	        long[]in=new long[n];for(int i=0;i<n;i++)in[i]=nextLong();
	        return in;
		}
		public Integer[] takearrobj(int n) throws IOException {
	        Integer[]in=new Integer[n];for(int i=0;i<n;i++)in[i]=nextInt();
	        return in;
		}
		public Long[] takearrlobj(int n) throws IOException {
	        Long[]in=new Long[n];for(int i=0;i<n;i++)in[i]=nextLong();
	        return in;
		}
		public String nextLine() throws IOException {
			return br.readLine();
		}
 
		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}
 
		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}
 
		public char nextChar() throws IOException {
			return next().charAt(0);
		}
 
		public Long nextLong() throws IOException {
			return Long.parseLong(next());
		}
 
		public boolean ready() throws IOException {
			return br.ready();
		}
 
		public void waitForInput() throws InterruptedException {
			Thread.sleep(3000);
		}
	}
}