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.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.FileNotFoundException;
import java.util.StringTokenizer;
import java.io.Writer;
import java.io.BufferedReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Asgar Javadov
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        FastWriter out = new FastWriter(outputStream);
        TaskD solver = new TaskD();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskD {
        int[][] all;
        long[][] sum;
        int[] L;

        public void solve(int testNumber, InputReader in, FastWriter out) {
            int n = in.nextInt();
            int m = in.nextInt();
            L = new int[n + 1];
            System.arraycopy(in.readIntArray(n - 1), 0, L, 2, n - 1);
            sum = new long[n + 1][];

            all = new int[n + 1][];

            dfs(1, n);

            while (m-- > 0) {
                int a = in.nextInt();
                int h = in.nextInt();
                out.println(query(a, h) + queryTree(a >> 1, h - L[a], a));
            }
        }

        private long query(int a, long h) {
            if (h <= 0) return 0L;
            int low = 0, high = all[a].length - 1;
            while (low <= high) {
                int mid = low + high >> 1;
                if (all[a][mid] >= h) {
                    high = mid - 1;
                } else {
                    low = mid + 1;
                }
            }
            long res = h;
            if (high >= 0) res = h * (high + 1) - sum[a][high];
            return res;
        }

        private long queryTree(int a, int h, int from) {
            if (a <= 0 || h <= 0) return 0L;
            int id = from == a << 1 ? a << 1 | 1 : a << 1;

            return (id < L.length ? query(id, h - L[id]) : 0L) + queryTree(a >> 1, h - L[a], a) + h;
        }

        private void dfs(int v, int n) {
            if (v * 2 > n) {
                all[v] = new int[1];
                sum[v] = new long[1];
                return;
            }

            int leftSon = v << 1;
            dfs(leftSon, n);

            int rightSon = v << 1 | 1;
            int pos = 1;
            if (rightSon <= n) {
                dfs(rightSon, n);
                all[v] = new int[1 + all[leftSon].length + all[rightSon].length];
                for (int i = 0, j = 0; i < all[leftSon].length && j < all[rightSon].length; ) {
                    int l = L[leftSon] + all[leftSon][i];
                    int r = L[rightSon] + all[rightSon][j];
                    if (l <= r) {
                        all[v][pos++] = l;
                        ++i;
                    } else {
                        all[v][pos++] = r;
                        ++j;
                    }
                    if (i == all[leftSon].length) {
                        for (; j < all[rightSon].length; ++j)
                            all[v][pos++] = L[rightSon] + all[rightSon][j];
                    }
                    if (j == all[rightSon].length) {
                        for (; i < all[leftSon].length; ++i)
                            all[v][pos++] = L[leftSon] + all[leftSon][i];
                    }
                }
            } else {
                all[v] = new int[1 + all[leftSon].length];
                for (int e : all[leftSon])
                    all[v][pos++] = e + L[leftSon];
            }


            sum[v] = new long[all[v].length];
            long prev = 0L;
            for (int i = 0; i < sum[v].length; ++i) {
                sum[v][i] += prev + all[v][i];
                prev = sum[v][i];
            }
        }

    }

    static class FastWriter extends PrintWriter {
        public FastWriter(OutputStream outputStream) {
            super(outputStream);
        }

        public FastWriter(Writer writer) {
            super(writer);
        }

        public FastWriter(String filename) throws FileNotFoundException {
            super(filename);
        }

    }

    static class InputReader extends BufferedReader {
        StringTokenizer tokenizer;

        public InputReader(InputStream inputStream) {
            super(new InputStreamReader(inputStream), 32768);
        }

        public InputReader(String filename) {
            super(new InputStreamReader(Thread.currentThread().getContextClassLoader().getResourceAsStream(filename)));
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(readLine());
                } catch (IOException e) {
                    throw new RuntimeException();
                }
            }
            return tokenizer.nextToken();
        }

        public Integer nextInt() {
            return Integer.valueOf(next());
        }

        public int[] readIntArray(int size) {
            int[] array = new int[size];
            for (int i = 0; i < size; i++)
                array[i] = nextInt();
            return array;
        }

    }
}