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.util.Arrays;
import java.util.Iterator;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

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

    static class TE {
        public void solve(int testNumber, MyScan in, PrintWriter out) {
            int n = in.nextInt();
            int m = in.nextInt();
            int[] length = in.na(n - 1);
            AList[] data = new AList[n];
            Arrays.setAll(data, l -> new AList());

            for (int k = n; k >= 1; k--) {
                data[k - 1].add(0);
                if (k * 2 + 1 <= n) {
                    data[k - 1] = data[k - 1].sortMergeShift(data[k * 2], length[k * 2 - 1]);
                }
                if (k * 2 <= n) {
                    data[k - 1] = data[k - 1].sortMergeShift(data[k * 2 - 1], length[k * 2 - 2]);
                }
            }


            long[][] sum = new long[n][];
            for (int s = 0; s < n; s++) {
                sum[s] = new long[data[s].size() + 1];
                for (int i = 0; i < data[s].size(); i++) {
                    sum[s][i + 1] = sum[s][i] + data[s].get(i);
                }
            }


            while (m-- > 0) {
                int tar = in.nextInt();
                int h = in.nextInt();
                long cur = calc(sum[tar - 1], data[tar - 1], h);
                while (tar > 1) {
                    int next = tar / 2;
                    h -= length[tar - 2];
                    cur += calc(sum[next - 1], data[next - 1], h);
                    cur -= calc(sum[tar - 1], data[tar - 1], h - length[tar - 2]);

                    tar = next;
                }
                out.println(cur);
            }

//        out.println(Arrays.toString(data));
        }

        private long calc(long[] sum, AList data, long offset) {
            if (offset <= 0 || data.size() == 0) return 0;
            int ct = 0;
            int e = data.size();
            while (ct + 1 < e) {
                int pos = (ct + e) / 2;
                int k = data.get(pos);
                if (k <= offset) {
                    ct = pos;
                } else {
                    e = pos;
                }
            }
            return offset * (ct + 1) - sum[ct + 1];
        }

    }

    static class MyScan {
        private final InputStream in;
        private byte[] inbuf = new byte[1024];
        public int lenbuf = 0;
        public int ptrbuf = 0;

        public MyScan(InputStream in) {
            this.in = in;
        }

        private int readByte() {
            if (lenbuf == -1) throw new InputMismatchException();
            if (ptrbuf >= lenbuf) {
                ptrbuf = 0;
                try {
                    lenbuf = in.read(inbuf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (lenbuf <= 0) return -1;
            }
            return inbuf[ptrbuf++];
        }

        public int[] na(int n) {
            int[] k = new int[n];
            for (int i = 0; i < n; i++) {
                k[i] = nextInt();
            }
            return k;
        }

        public int nextInt() {
            int num = 0, b;
            boolean minus = false;
            while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) ;
            if (b == '-') {
                minus = true;
                b = readByte();
            }

            while (true) {
                if (b >= '0' && b <= '9') {
                    num = num * 10 + (b - '0');
                } else {
                    return minus ? -num : num;
                }
                b = readByte();
            }
        }

    }

    static class AList implements Iterable<Integer> {
        int[] data;
        int size = 0;

        public AList(int n) {
            this.data = new int[Math.max(Integer.highestOneBit(n - 1) << 1, 4)];
        }

        public AList() {
            this(4);
        }

        public AList(int[] data) {
            this(data.length);
            System.arraycopy(data, 0, this.data, 0, data.length);
            size = data.length;
        }

        AList(int[] data, int s) {
            this.data = data;
            this.size = s;
        }

        public AList sortMergeShift(AList sorted, int p) {
            AList ns = new AList();
            int f = 0;
            int l = 0;
            while (f < sorted.size || l < size) {
                if (f == sorted.size || l != size && (sorted.get(f) + p) >= data[l]) {
                    ns.add(data[l++]);
                } else {
                    ns.add(sorted.get(f++) + p);
                }
            }
            return ns;
        }

        public void add(int k) {
            if (size == data.length) {
                data = Arrays.copyOf(data, data.length << 1);
            }
            data[size++] = k;
        }


        public Iterator<Integer> iterator() {


            int[] m = new int[1];
            return new Iterator<Integer>() {

                public boolean hasNext() {
                    return m[0] < AList.this.size;
                }


                public Integer next() {
                    return AList.this.data[m[0]++];
                }
            };
        }


        public String toString() {
            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < size; i++) {
                sb.append(data[i]).append(' ');
            }
            return sb.toString();
        }

        public int size() {
            return size;
        }

        public int get(int i) {
            return data[i];
        }

    }
}