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:
/*
 * 
 * @Author  Ajudiya_13(Bhargav Girdharbhai Ajudiya)
 * Dhirubhai Ambani Institute of Information And Communication Technology 
 * 
 */


import java.util.*;
import java.io.*;
import java.lang.*;

public class Code259
{
	public static long[][] segment;
	public static long[][] prefix;
	public static int n;
	public static int m;
	public static long[] weight;
	
	public static void dfs(int s)
	{
		if(2*s>n)
		{
			segment[s] = new long[1];
			prefix[s] = new long[1];
			return;
		}
		
		dfs(2*s);
		if(2*s+1<=n)
		{
			dfs(2*s+1);
			int left = 2*s;
			int right = 2*s+1;
			
			segment[s] = new long[1+ segment[left].length + segment[right].length];
			long l1 = weight[2*s-1];
			long l2 = weight[2*s];
			
			int i = 0;
			int j = 0;
			int k = 1;
			
			
			while(i<segment[left].length && j <segment[right].length)
			{
				if(segment[left][i]+l1 <= segment[right][j]+l2)
				{
					segment[s][k] = segment[left][i]+l1;
					i++;
					k++;
				}
				else
				{
					segment[s][k] = segment[right][j]+l2;
					j++;
					k++;
				}
			}
			
			while(i<segment[left].length)
			{
				segment[s][k] = segment[left][i]+l1;
				i++;
				k++;
			}
			
			while(j<segment[right].length)
			{
				segment[s][k] = segment[right][j]+l2;
				j++;
				k++;
			}
		}
		
		else
		{
			int left = 2*s;
			long l1 = weight[2*s-1];
			segment[s] = new long[1+ segment[left].length];
			for(int i=0;i<segment[left].length;i++)
				segment[s][i+1] = segment[left][i] +	 l1;
		}
		
		prefix[s] = new long[segment[s].length];
		prefix[s][0] = segment[s][0];
		for(int j=1;j<segment[s].length;j++)
			prefix[s][j] = prefix[s][j-1] + segment[s][j];
	}
	
	public static long BinarySearch(int Ai,long H)
	{
		int start = 0;
		int end = segment[Ai].length-1;
		
		int ans = -1;
		while(start<=end)
		{
			int mid = (start+end)/2;
			if(segment[Ai][mid]<=H)
			{
				ans = mid;
				start = mid + 1;
			}
			else
				end = mid-1;
		}
		
		if(ans!=-1)
			return (H*(long)(ans) - prefix[Ai][ans]);
		return 0;
	}
	
	public static long query(int Ai,long H)
	{
		long ans = H;
		ans += BinarySearch(Ai, H);
		int child = Ai;
		int parent = Ai/2;
		
		while(parent>0)
		{
			long length = weight[child-1];
			if(H>=length)
				ans += H-length;
			else
				return ans;
			H-=length;
			
			if(child==2*parent)
			{
				if(2*parent<n)
				{
					length = weight[2*parent];
					if(H>=length)
					{
						ans += H-length;
						ans += BinarySearch(2*parent+1, H-length);
					}
				}
				child = parent;
				parent = parent/2;
			}
			
			else
			{
				length = weight[2*parent-1];
				if(H>=length)
				{
					ans += H-length;
					ans += BinarySearch(2*parent, H-length);
				}
				child = parent;
				parent = parent/2;
			}
		}
		
		return ans;
	}
	public static void main(String[] args)
	{
		InputReader in = new InputReader(System.in);
		PrintWriter pw = new PrintWriter(System.out);

		n = in.nextInt();
		m = in.nextInt();
		
		weight = new long[n];
		for(int i=1;i<n;i++)
			weight[i] = in.nextLong();
		
		segment = new long[n+1][];
		prefix = new long[n+1][];
		
		dfs(1);
		for(int i=0;i<m;i++)
		{
			int Ai = in.nextInt();
			long H = in.nextLong();
			pw.println(query(Ai, H));
		}
		pw.flush();
		pw.close();
	}
	
	static class InputReader 
	{
		 
		private final InputStream stream;
		private final byte[] buf = new byte[8192];
		private int curChar, snumChars;
		private SpaceCharFilter filter;
 
		public InputReader(InputStream stream) 
		{
			this.stream = stream;
		}
 
		public int snext() 
		{
			if (snumChars == -1)
				throw new InputMismatchException();
			if (curChar >= snumChars) 
			{
				curChar = 0;
				try 
				{
					snumChars = stream.read(buf);
				} 
				catch (IOException e) 
				{
					throw new InputMismatchException();
				}
				if (snumChars <= 0)
					return -1;
			}
			return buf[curChar++];
		}
 
		public int nextInt() 
	    {
			int c = snext();
			while (isSpaceChar(c)) 
			{
				c = snext();
			}
			int sgn = 1;
			if (c == '-')
		    {
				sgn = -1;
				c = snext();
			}
			int res = 0;
			do 
			{
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = snext();
			} while (!isSpaceChar(c));
			return res * sgn;
		}
 
		public long nextLong()
	    {
			int c = snext();
			while (isSpaceChar(c)) 
			{
				c = snext();
			}
			int sgn = 1;
			if (c == '-') 
			{
				sgn = -1;
				c = snext();
			}
			long res = 0;
			do 
			{
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = snext();
			} while (!isSpaceChar(c));
			return res * sgn;
		}
 
		public int[] nextIntArray(int n) 
		{
			int a[] = new int[n];
			for (int i = 0; i < n; i++) 
			{
				a[i] = nextInt();
			}
			return a;
		}
 
		public String readString()
	    {
			int c = snext();
			while (isSpaceChar(c)) 
			{
				c = snext();
			}
			StringBuilder res = new StringBuilder();
			do 
			{
				res.appendCodePoint(c);
				c = snext();
			} while (!isSpaceChar(c));
			return res.toString();
		}
 
		public String nextLine() 
		{
			int c = snext();
			while (isSpaceChar(c))
				c = snext();
			StringBuilder res = new StringBuilder();
			do 
			{
				res.appendCodePoint(c);
				c = snext();
			} while (!isEndOfLine(c));
			return res.toString();
		}
 
		public boolean isSpaceChar(int c) 
		{
			if (filter != null)
				return filter.isSpaceChar(c);
			return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
		}
 
		private boolean isEndOfLine(int c) 
		{
			return c == '\n' || c == '\r' || c == -1;
		}
 
		public interface SpaceCharFilter
	    {
			public boolean isSpaceChar(int ch);
		}
	}
	
	public static long mod = 1000000007;
	public static int d;
	public static int p;
	public static int q;
	
	static class pair implements Comparable<pair>
	{
		Integer x, y;
		pair(int x,int y)
		{
			this.x=x;
			this.y=y;
		}
		
		public int compareTo(pair o) {
			int result = x.compareTo(o.x);
			if(result==0)
				result = y.compareTo(o.y);
			
			return result;
		}  
		
		public String toString()
		{
			return x+" "+y;
		}
		
		public boolean equals(Object o)
		{
			if (o instanceof pair)
		    {
				pair p = (pair)o;
				return p.x == x && p.y == y ;
			}
			return false;
		}
		
		public int hashCode()
		{
			return new Long(x).hashCode()*31 + new Long(y).hashCode();
		}
	}
}