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:
import java.io.*;
import java.util.*;

public class A implements Runnable{
	public static void main (String[] args) {new Thread(null, new A(), "_cf", 1 << 28).start();}

	ArrayList<Edge>[] adj;
	int[] par;
	long[][] sum;
	long oo = (long)1e18;
	
	public void run() {
		FastScanner fs = new FastScanner();
		PrintWriter out = new PrintWriter(System.out);

		int n = fs.nextInt();
		int q = fs.nextInt();
		adj = new ArrayList[n];
		for(int i = 0; i < n; i++)
			adj[i] = new ArrayList<>();
		
		for(int i = 1; i < n; i++) {
			int u = i + 1;
			int v = (i + 1) / 2;
			int len = fs.nextInt();
			u--; v--;
//			System.out.println(u + " " + v);
			adj[u].add(new Edge(v, len));
			adj[v].add(new Edge(u, len));
		}
		
		par = new int[n];
		sum = new long[n][];
		dfs(0, -1);
		
//		for(int i = 0; i < n; i++) {
//			System.out.println("For node " + (i+1));
//			System.out.println(merge[i].length + " " + Arrays.toString(merge[i]));
//			System.out.println(sum[i].length + " " + Arrays.toString(sum[i]));
//		}
//		System.out.println();
		
		while(q-->0) {
			int u = fs.nextInt()-1;
			int h = fs.nextInt();
			long res = 0;
			
			//process my entire array
			res = best(sum[u], h);
//			System.out.printf("%d %d\n", u+1, res);
			
			//go until the root and process the opposite child
			int last = u;
			while(u >= 0 && last != 0) {
				u = ((u + 1) / 2) - 1;
				res += Math.max(0, h - par[last]);
				h -= par[last];
				int left = 2 * u + 1;
				int right = 2 * u + 2;
//				System.out.println(u + " " + left + " " + right + " " + last);
//				System.out.printf("Cur %d Left %d Right %d h %d Last %d Res %d\n", u, left, right, h, last, res);
				if(left == last) {
					//iterate on right child of current u
//					System.out.println(right + " " + Arrays.toString(merge[right]) + " " + Arrays.toString(sum[right]) + " " + (h - par[right]));
//					System.out.println("Best? " + best(merge[right], sum[right], h - par[right]));
//					System.out.println(right);
					if(right < n)
						res += best(sum[right], h - par[right]);
				}
				else {
					//iterate on left child of current u
					if(left < n)
						res += best(sum[left], h - par[left]);
				}
				last = u;
				if(u == 0) break;
			}
			
			out.println(res);
//			System.out.println();
			
		}
		
		out.close();
	}
	
	long best (long[] sum, long lim) {
		int res = -1;
		if(lim < 0) return 0;
		
		int lo = 0, hi = sum.length - 1;
		for(int bs = 0; bs < 50 && lo <= hi; bs++) {
			int mid = (lo + hi) >> 1;
			long check = lim;
//			System.out.println(lo + " " + hi + " " + mid + " " + check + " " + sum[mid]);
			if(check >= sum[mid] - (mid-1 >= 0 ? sum[mid-1] : 0)) {
				res = Math.max(res, mid);
				lo = mid+1;
			}
			else {
				hi = mid-1;
			}
		}
//		System.out.println(res + "!");
//		System.out.println(lim * (res+1));
//		System.out.println(sum[res]);
//		System.out.println();
		
		if(res == -1) return 0;
		return lim*(res+1) - sum[res];
	}
	
	void dfs (int u, int p) {
		int v = 0;
		int leftChild = -1, rightChild = -1;
		long len1 = -1, len2 = -1;
		for(Edge i : adj[u]) {
			if(i.v == p) continue;
			v++;
			if(leftChild < 0) {
				leftChild = i.v;
				len1 = i.we;
			}
			else {
				rightChild = i.v;
				len2 = i.we;
			}
			par[i.v] = (int)i.we;
			dfs(i.v, u);
		}
		
		if(v == 0) {
			//leaf
			sum[u] = new long[1];
			return;
		}
		
		if(rightChild == -1) {
			//just copy left child's array + dist
			int len = sum[leftChild].length + 1;
			sum[u] = new long[len];
			for(int i = 1; i < len; i++) {
				sum[u][i] += sum[u][i-1];
				sum[u][i] = len1 + sum[leftChild][i-1];
			}
			return;
		}
		
		//my children's arrays are created so let's merge sort
		int ptr1 = 0, ptr2 = 0, idx = 1;
		int len = sum[leftChild].length + sum[rightChild].length + 1;
		sum[u] = new long[len];
		//keep an extra position at the beginning for the distance to myself which is always 0
		while(idx < len) {
			long leftMin = oo;
			long rightMin = oo;
			if(ptr1 < sum[leftChild].length) {
				leftMin = sum[leftChild][ptr1] - (ptr1-1 >= 0 ? sum[leftChild][ptr1-1] : 0) + len1;
			}
			if(ptr2 < sum[rightChild].length) {
				rightMin = sum[rightChild][ptr2] - (ptr2-1 >= 0 ? sum[rightChild][ptr2-1] : 0) + len2;
			}
			
			if(leftMin < rightMin) {
				sum[u][idx] += leftMin;
				ptr1++;
			}
			else {
				sum[u][idx] = rightMin;
				ptr2++;
			}
			sum[u][idx] += sum[u][idx-1];
			idx++;
		}
	}
	
	class Edge {
		int v;
		long we;
		Edge (int a, int b) {
			v = a;
			we = b;
		}
	}
	
	void sort (int[] a) {
		int n = a.length;
		for(int i = 0; i < 1000; i++) {
			Random r = new Random();
			int x = r.nextInt(n), y = r.nextInt(n);
			int temp = a[x];
			a[x] = a[y];
			a[y] = temp;
		}
		Arrays.sort(a);
	}

	class FastScanner {
		BufferedReader br;
		StringTokenizer st;
		public FastScanner() {
			try	{
				br = new BufferedReader(new InputStreamReader(System.in));
				//				br = new BufferedReader(new FileReader("wifi.in"));
				st = new StringTokenizer("");
			} catch (Exception e){e.printStackTrace();}
		}
		public String next() {
			if (st.hasMoreTokens())	return st.nextToken();
			try {st = new StringTokenizer(br.readLine());}
			catch (Exception e) {e.printStackTrace();}
			return st.nextToken();
		}
		public int nextInt() {return Integer.parseInt(next());}
		public long nextLong() {return Long.parseLong(next());}
		public double nextDouble() {return Double.parseDouble(next());}

		public String nextLine() {
			String line = "";
			try {line = br.readLine();}
			catch (Exception e) {e.printStackTrace();}
			return line;
		}
		public Integer[] nextIntegerArray(int n) {
			Integer[] a = new Integer[n];
			for(int i = 0; i < n; i++) a[i] = nextInt();
			return a;
		}
		public int[] nextIntArray(int n) {
			int[] a = new int[n];
			for(int i = 0; i < n; i++) a[i] = nextInt();
			return a;
		}
		public char[] nextCharArray() {return nextLine().toCharArray();}
	}

}