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.math.BigInteger;
import java.util.*;
import java.util.concurrent.TimeUnit;

public class d894 implements Runnable{
	
    public static void main(String[] args) {
    	try{
            new Thread(null, new d894(), "process", 1<<26).start();
        }
        catch(Exception e){
            System.out.println(e);
        }
    }
	public void run() {
		FastReader scan = new FastReader();
        PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
		//PrintWriter out = new PrintWriter("file.out");
		Task solver = new Task();
//		int t = scan.nextInt();
		int t = 1;
		for(int i = 1; i <= t; i++) solver.solve(i, scan, out);
		out.close();
	}

	static class Task {
		static final int oo = Integer.MAX_VALUE;
		static final long OO = Long.MAX_VALUE;

		int[] w;
		int[][] dists;
		int N;
		
		public void solve(int testNumber, FastReader sc, PrintWriter out) {
			N = sc.nextInt();
			int M = sc.nextInt();
			
			w = new int[N];
			for(int i = 1; i < N; i++) {
				w[i] = sc.nextInt();
//				w[i] = (int)(Math.random() * 100000);
			}
			
			dists = new int[N+1][1];
			
			for(int i = N; i > N/2; i--) {
				dists[i][0] = 0;
			}
			for(int i = N/2; i > 0; i--) {
				
				if(i * 2 + 1 > N) {
					dists[i] = new int[1 + dists[i*2].length];
					dists[i][0] = 0;
					for(int j = 0; j < dists[i*2].length; j++) {
						dists[i][j+1] = dists[i*2][j] + w[i*2-1];
					}
				} else {
				
					dists[i] = new int[1 + dists[i*2].length + dists[i*2+1].length];
					dists[i][0] = 0;
					
					for(int j = 0, k = 0, l = 1; j < dists[i*2].length || k < dists[i*2+1].length; l++) {
						if(j >= dists[i*2].length) {
							dists[i][l] = dists[i*2+1][k++] + w[i*2];
							continue;
						}
						if(k >= dists[i*2+1].length) {
							dists[i][l] = dists[i*2][j++] + w[i*2-1];
							continue;
						}
						if(dists[i*2][j] + w[i*2-1] < dists[i*2+1][k] + w[i*2]) {
							dists[i][l] = dists[i*2][j++] + w[i*2-1];
						} else {
							dists[i][l] = dists[i*2+1][k++] + w[i*2];
						}	
					}
				}
			}

//			for(int[] each: dists)
//				dbg(each);
			
			long[][] pSum = new long[N+1][1];
			for(int i = 0; i < pSum.length; i++) {
				pSum[i] = new long[dists[i].length];
				pSum[i][0] = dists[i][0];
				for(int j = 1; j < pSum[i].length; j++) {
					pSum[i][j] = pSum[i][j-1] + dists[i][j];
				}
			}

//			for(int[] each: pSum)
//				dbg(each);
			
			
			while(M --> 0) {
				int a = sc.nextInt();
				int h = sc.nextInt();
//				int a = (int)(Math.random() * (N-1) + 1);
//				int h = (int)(Math.random() * 10000000);
				
				long sum = 0;
				
				
				int i = bs(dists[a], h);
				sum += (long)i * h + h - pSum[a][i];
				
//				dbg(sum);
				
				while(a != 1) {
					h -= w[a-1];
					if(h <= 0)
						break;
					
					sum += h;
					int other = a ^ 1;
					if(other <= N && h > w[other-1]) {
						i = bs(dists[other], h - w[other-1]);
						sum += (i+1l) * (h - w[other-1]) - pSum[other][i];
					}
					
					a /= 2;
				}
				
				out.println(sum);
			}
		}
		
		int bs(int[] arr, int v) {
			int ans = -1;
			int lo = 0, hi = arr.length-1;
			
			while (lo <= hi) {
				int mid = (lo + hi) / 2;
				if (arr[mid] <= v) {
					ans = mid;
					lo = mid+1;
				} else {
					hi = mid-1;
				}
			}
			return ans;
		} 
	}
	static long modInverse(long N, long MOD) {
		return binpow(N, MOD - 2, MOD);
	}
	static long modDivide(long a, long b, long MOD) {
		a %= MOD;
		return (binpow(b, MOD-2, MOD) * a) % MOD;
	}
	static long binpow(long a, long b, long m) {
		a %= m;
		long res = 1;
		while (b > 0) {
			if ((b & 1) == 1)
				res = res * a % m;
			a = a * a % m;
			b >>= 1;
		}
		return res;
	}
	static int[] reverse(int a[]) 
    { 
        int[] b = new int[a.length]; 
        for (int i = 0, j = a.length; i < a.length; i++, j--) { 
            b[j - 1] = a[i]; 
        } 
        
        return b;
    }
	static long[] reverse(long a[]) 
    { 
        long[] b = new long[a.length]; 
        for (int i = 0, j = a.length; i < a.length; i++, j--) { 
            b[j - 1] = a[i]; 
        } 
        
        return b;
    }
	
	static void shuffle(Object[] a) {
		Random get = new Random();
		for (int i = 0; i < a.length; i++) {
			int r = get.nextInt(a.length);
			Object temp = a[i];
			a[i] = a[r];
			a[r] = temp;
		}
	}
	
	static void shuffle(int[] a) {
		Random get = new Random();
		for (int i = 0; i < a.length; i++) {
			int r = get.nextInt(a.length);
			int temp = a[i];
			a[i] = a[r];
			a[r] = temp;
		}
	}
	static void shuffle(long[] a) {
		Random get = new Random();
		for (int i = 0; i < a.length; i++) {
			int r = get.nextInt(a.length);
			long temp = a[i];
			a[i] = a[r];
			a[r] = temp;
		}
	}
	
	static class tup {
		long a, b;
		tup(long a,long b){
			this.a=a;
			this.b=b;
		}
		public tup() {
		}
		
		@Override
	    public int hashCode() {
			return Objects.hash(a, b);
	    }
 
	    @Override
	    public boolean equals(Object obj) {
	    	if (this == obj)
                return true;
	    	if (obj == null)
                return false;
	    	if (getClass() != obj.getClass())
                return false;
	    	tup other = (tup) obj;
	    	return a==other.a && b==other.b;
	    }
	    
	    @Override
	    public String toString() {
	    	return a + " " + b;
	    }
	}

	static class FastReader {
		BufferedReader br;
		StringTokenizer st;

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

		public FastReader(String s) throws FileNotFoundException {
			br = new BufferedReader(new FileReader(new File(s)));
		}

		String next() {
			while (st == null || !st.hasMoreElements()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

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

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

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

		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return str;
		}
		
		int[] readArray(int size) {
			int[] a = new int[size];
			for(int i = 0; i < size; i++) {
				a[i] = nextInt();
			}
			return a;
		}
		
		long[] readLongArray(int size) {
			long[] a = new long[size];
			for(int i = 0; i < size; i++) {
				a[i] = nextLong();
			}
			return a;
		}
	}
	
	static void dbg(int[] arr) {
		System.out.println(Arrays.toString(arr));
	}
	static void dbg(long[] arr) {
		System.out.println(Arrays.toString(arr));
	}
	static void dbg(boolean[] arr) {
		System.out.println(Arrays.toString(arr));
	}

	static void dbg(Object... args) {
        for (Object arg : args)
            System.out.print(arg + " ");
        System.out.println();
    }
}