Problem: Ralph is in the Binary Country. The Binary Country consists of n cities and (n - 1) bidirectional roads connecting the cities. The roads are numbered from 1 to (n - 1), the i-th road connects the city labeled <image> (here ⌊ x⌋ denotes the x rounded down to the nearest integer) and the city labeled (i + 1), and the length of the i-th road is Li.

Now Ralph gives you m queries. In each query he tells you some city Ai and an integer Hi. He wants to make some tours starting from this city. He can choose any city in the Binary Country (including Ai) as the terminal city for a tour. He gains happiness (Hi - L) during a tour, where L is the distance between the city Ai and the terminal city.

Ralph is interested in tours from Ai in which he can gain positive happiness. For each query, compute the sum of happiness gains for all such tours.

Ralph will never take the same tour twice or more (in one query), he will never pass the same city twice or more in one tour.

Input

The first line contains two integers n and m (1 ≤ n ≤ 106, 1 ≤ m ≤ 105).

(n - 1) lines follow, each line contains one integer Li (1 ≤ Li ≤ 105), which denotes the length of the i-th road.

m lines follow, each line contains two integers Ai and Hi (1 ≤ Ai ≤ n, 0 ≤ Hi ≤ 107).

Output

Print m lines, on the i-th line print one integer — the answer for the i-th query.

Examples

Input

2 2
5
1 8
2 4


Output

11
4


Input

6 4
2
1
1
3
2
2 4
1 3
3 2
1 7


Output

11
6
3
28

Note

Here is the explanation for the second sample.

Ralph's first query is to start tours from city 2 and Hi equals to 4. Here are the options:

  * He can choose city 5 as his terminal city. Since the distance between city 5 and city 2 is 3, he can gain happiness 4 - 3 = 1. 
  * He can choose city 4 as his terminal city and gain happiness 3. 
  * He can choose city 1 as his terminal city and gain happiness 2. 
  * He can choose city 3 as his terminal city and gain happiness 1. 
  * Note that Ralph can choose city 2 as his terminal city and gain happiness 4. 
  * Ralph won't choose city 6 as his terminal city because the distance between city 6 and city 2 is 5, which leads to negative happiness for Ralph. 



So the answer for the first query is 1 + 3 + 2 + 1 + 4 = 11.

Solution (in JAVA):

Solution:
//package ;
import java.io.*;
import java.util.*;

public class Zizo {
	static int n,m;
	static int[]child,idx,adjList[];
	static long[][]roads,pre;
	public static void main(String[] args) throws IOException {
		Scanner sc = new Scanner();
		PrintWriter pw = new PrintWriter(System.out);
		n=sc.nextInt();m=sc.nextInt();
		int u=1,v=2;
		adjList=new int[n+2][2];
		child=new int[n+2];
		roads=new long[n+2][];
		pre=new long[n+2][];
		idx=new int[n+2];
		for(int i=1;i<n;i++)
		{
			int cost=sc.nextInt();
			if((v&1)==0)
				adjList[u][0]=cost;
			else if((v&1)==1)
				adjList[u++][1]=cost;
			v++;
		}
		v--;
		while(v>1)
		{
			int p=v/2;
			if(child[p]==0)
			{
				child[p]+=child[v]+1;
				if((v&1)==1)
					child[p]+=child[v-1]+1;
				roads[p]=new long[child[p]];
			}
			int cost=adjList[p][v&1];
			int start=idx[p];
			int i=idx[p];
			roads[p][i++]=cost;
			if(roads[v]!=null)
				for(long x:roads[v])
					roads[p][i++]=x+cost;
			
			idx[p]=i;
			if((v&1)==0)//left child
			{
				merge(roads[p], 0, roads[p].length-1,start);
				pre[p]=new long[roads[p].length];
				if(roads[p].length>0)
					pre[p][0]=roads[p][0];
				for(int j=1;j<pre[p].length;j++)
					pre[p][j]=pre[p][j-1]+roads[p][j];
			}	
			v--;
		}
		while(m-->0)
		{
			u=sc.nextInt();int k=sc.nextInt();
			long ans=k;
			ans+=getAll(u, k);
			if(u==1)
			{
				pw.println(ans);
				continue;
			}
			int p=u/2;
			long CostP=adjList[p][u&1];
			while(true)
			{
				if(k>=CostP)
				{	
					ans=ans+(k-CostP);
					if((u&1)==0)//i am in the left
					{
						if(adjList[p][1]!=0 && adjList[p][1]+CostP <=k)
						{
							ans=ans+(k-(adjList[p][1]+CostP));
							ans+=getAll((p<<1)+1, (int)(k-(adjList[p][1]+CostP)));
						}
					}
					else
					{
						if(adjList[p][0]!=0 && adjList[p][0]+CostP <=k)
						{
							ans=ans+(k-(adjList[p][0]+CostP));
							ans+=getAll(p<<1, (int)(k-(adjList[p][0]+CostP)));
						}
					}
				}
				u=p;
				if(u==1)
					break;
				p=u/2;
				CostP+=adjList[p][u&1];
			}
			pw.println(ans);
		}
		pw.close();
	}
	static long getAll(int u,int k)
	{		
		long[]a=roads[u];
		if(a==null)return 0l;
		int hi=a.length-1,lo=0;
		int indx=-1;
		while(lo<=hi && hi>=0 && lo<a.length)
		{
			int mid=lo+hi>>1;
			if(a[mid]>k)
				hi=mid-1;
			else
			{
				indx=Math.max(indx, mid);
				lo=mid+1;
			}
		}
		if(indx==-1)
			return 0;
		return 1l*k*(indx+1)-pre[u][indx];
	}
	
	public static void merge(long []a , int start, int end,int mid)
	{
		int i=0;
		int con=mid;int k=start;
		long tm[]=new long[end-start+1];
		while(start<con && mid<=end)
		{
			if(a[start]>a[mid])
				tm[i++]=a[mid++];
			else
				tm[i++]=a[start++];
		}
		while(mid<=end)
			tm[i++]=a[mid++];
		while(start<con)
			tm[i++]=a[start++];
		for(int j=0;j<tm.length;j++)
			a[k++]=tm[j];
	}
	static class Scanner {
		BufferedReader br;
		StringTokenizer st;

		Scanner() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String next() throws IOException {
			while (st == null || !st.hasMoreTokens()) {
				st = new StringTokenizer(br.readLine());
			}
			return st.nextToken();
		}

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

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

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

		String nextLine() throws IOException {
			return br.readLine();
		}

		boolean hasnext() throws IOException {
			return br.ready();
		}

	}
}