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.OutputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.io.BufferedWriter;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

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

    static class TaskD {
        int n;
        int m;
        int a;
        int h;
        int max_left_val;
        int[] path_length = new int[1111111];
        int[] start_pos = new int[1111111];
        int[] sz = new int[1111111];
        int[] lr_start_pos = new int[1111111];
        int[] lr_sz = new int[1111111];
        int[] left;
        int[] right;
        int[] both;
        long[] leftsum;
        long[] rightsum;

        int fun(int node, int limit,int from) {
            
            int lo = lr_start_pos[node];
            int hi = lr_start_pos[node]+sz[node]-1;

            //System.out.println(node+" "+lo+" "+hi);

            // for(int i=lo;i<=hi;i++){
            //     System.out.print(both[lo]+ " ");
            // }
            // System.out.println();

            int mid;
            while (lo <= hi) {
                mid = (lo + hi)/2;

                int val;

                if(from==0){
                    val = right[mid];
                }
                else if(from ==1){
                    val = left[mid];
                }
                else{
                    val=both[mid];
                }

                if (val <= limit) {
                    lo = mid + 1;
                } else {
                    hi = mid - 1;
                }
            }
            // System.out.println(node+" "+(lo-start_pos[node]));sz

            return lo-lr_start_pos[node];

        }

        long calculate_sum(int node, int from, int limit) {
            //ystem.out.println(node+" "+from+" "+limit);
            if (limit < 0) return 0;
            if (node == 0) return 0;
            long sum = 0;

            if (from == 2) {
                sum+=limit;
                int id = fun(node, limit,1);
                //System.out.println(id);
                if (id != 0) {
                    sum += -leftsum[lr_start_pos[node]+id - 1] + 1L*id * limit;
                }
                
                id = fun(node, limit,0);

                if (id != 0) {
                    // System.out.println(lr_start_pos[node]);
                    // System.out.println(lr_start_pos.length);
                    sum += -rightsum[lr_start_pos[node]+id - 1] + 1L*id * limit;
                }

                sum += calculate_sum(node / 2, node % 2, limit - path_length[node]);
            } else if (from == 1) {
                sum += limit;
                int id = fun(node, limit,from);
                if (id != 0) {
                    sum += -leftsum[lr_start_pos[node]+id - 1] + 1L*id * limit;
                }
                sum += calculate_sum(node / 2, node % 2, limit - path_length[node]);
            } else if (from == 0) {
                sum += limit;
                int id = fun(node, limit,from);
                if (id != 0) {
                    sum += -rightsum[lr_start_pos[node]+id - 1] + 1L*id * limit;
                }
                sum += calculate_sum(node / 2, node % 2, limit - path_length[node]);
            }
            return sum;
        }

        void pre_calculation(int node, int power) {

            // System.out.println("hic");

            if (node > n) return;
            pre_calculation(node * 2, power - 1);
            pre_calculation(node * 2 + 1, power - 1);
            

            int lsz,rsz;
            lsz = node*2<=n ? sz[node*2]:0;
            rsz = (node*2+1)<=n ? sz[node*2+1]:0;
            
            int id = 0;
            // System.out.println(lsz);
            while (node*2<=n && (id < lsz)) {
                if (both[start_pos[node*2]+id] == Integer.MAX_VALUE) break;
                int tem = both[start_pos[node*2]+id] + path_length[node * 2];
                if(tem>10000000)tem=Integer.MAX_VALUE/2;
                //if(start_pos[node]<max_left_val){
                    // System.out.println(lr_start_pos[node]);
                    // System.out.println(start_pos[node]);
                    // System.out.println(left.length);
                    // System.out.println(id);
                    left[lr_start_pos[node]+id] = tem;
                    leftsum[lr_start_pos[node]+id] = (id == 0) ? tem : leftsum[lr_start_pos[node]+id - 1] + tem;
                //}
                
                id++;
            }
            id = 0;
            while (node*2+1<=n && (id < rsz)) {
                if (both[start_pos[node*2+1]+id] == Integer.MAX_VALUE) break;
                int tem = both[start_pos[node*2+1]+id] + path_length[node * 2 + 1];
                if(tem>10000000)tem=Integer.MAX_VALUE/2;
                //if(start_pos[node]<max_left_val){
                    right[lr_start_pos[node]+id] = tem;
                    rightsum[lr_start_pos[node]+id] = (id == 0) ? tem : rightsum[lr_start_pos[node]+id - 1] + tem;
               // }
                id++;
            }

            int cid = start_pos[node];
            both[cid] = 0;
            long last = 0L;
            int p1 = 0, p2 = 0;
            cid++;
            while (((node*2<=n && p1 < sz[node*2]) || (node*2+1<=n &&p2 < sz[node*2+1]))) {
                if ((node*2<=n && p1 < sz[node*2]) && (node*2+1<=n &&p2 < sz[node*2+1])) {
                    if (left[lr_start_pos[node]+p1] <= right[lr_start_pos[node]+p2]) {
                        if (left[lr_start_pos[node]+p1] == Integer.MAX_VALUE) break;
                        both[cid] = left[lr_start_pos[node]+p1];
                        last = left[lr_start_pos[node]+p1] + last;
                        cid++;
                        p1++;
                    } else {
                        if (right[lr_start_pos[node]+p2] == Integer.MAX_VALUE) break;
                        both[cid] = right[lr_start_pos[node]+p2];
                        last = right[lr_start_pos[node]+p2] + last;
                        cid++;
                        p2++;
                    }
                } else if ((node*2<=n && p1 < sz[node*2])) {
                    if (left[lr_start_pos[node]+p1] == Integer.MAX_VALUE) break;
                    both[cid] = left[lr_start_pos[node]+p1];
                    last = left[lr_start_pos[node]+p1] + last;
                    cid++;
                    p1++;
                } else {
                    if (right[lr_start_pos[node]+p2] == Integer.MAX_VALUE) break;
                    both[cid] = right[lr_start_pos[node]+p2];
                    last = right[lr_start_pos[node]+p2] + last;
                    cid++;
                    p2++;
                }
            }
        }

    private static final long MEGABYTE = 1024L * 1024L;

    public static long bytesToMegabytes(long bytes) {
        return bytes / MEGABYTE;
    }

        public void solve(int testNumber, InputReader in, OutputWriter out) {

            //final long startTime = System.currentTimeMillis();
            n = in.readInt();
            m = in.readInt();
            //  /n=1000000;
            for (int path = 2; path <= n; path++) {
                path_length[path] = in.readInt();
                //  path_length[path] = path;
            }

            int power = 0;
            int tem = n;
            while (tem > 0) {
                tem /= 2;
                power++;
            }
            left = new int[(power)*(1<<(power-1))];
            right = new int[(power)*(1<<(power-1))];
            both = new int[power*(1<<power)];
            leftsum = new long[(power)*(1<<(power-1))];
            rightsum = new long[(power)*(1<<(power-1))];
            Arrays.fill(both, Integer.MAX_VALUE);
            Arrays.fill(left, Integer.MAX_VALUE);
            Arrays.fill(leftsum, Integer.MAX_VALUE);
            Arrays.fill(right, Integer.MAX_VALUE);
            Arrays.fill(rightsum, Integer.MAX_VALUE);

            sz[1]=1<<power;
            start_pos[1]=0;
            int temp=1<<power;
            for(int i=2;i<=n;i++){
                sz[i]=sz[i/2]/2;
                start_pos[i] = temp;
                temp+=sz[i];
            }

            lr_sz[1]=1<<(power-1);
            lr_start_pos[1]=0;
            temp=1<<(power-1);
            for(int i=2;i<=n;i++){
                lr_sz[i]=lr_sz[i/2]/2;
                lr_start_pos[i] = temp;
                temp+=lr_sz[i];
            }

             pre_calculation(1, power);

            //  System.out.println("hic");

        //     Runtime runtime = Runtime.getRuntime();
        // // Run the garbage collector
        // runtime.gc();
        // // Calculate the used memory
        // long memory = runtime.totalMemory() - runtime.freeMemory();
        // System.out.println("Used memory is bytes: " + memory);
        // System.out.println("Used memory is megabytes: "
        //         + bytesToMegabytes(memory));
        // System.out.println(bytesToMegabytes(sz.length/2+path_length.length/2+ both.length/2 + start_pos.length/2 + left.length/2+right.length/2+rightsum.length+leftsum.length)*8);

            for (int test = 0; test < m; test++) {
                a = in.readInt();
                h = in.readInt();
                out.printLine(calculate_sum(a, 2, h));
            }

            // final long endTime = System.currentTimeMillis();

            // System.out.println("Total execution time: " + (endTime - startTime) );
        }

    }

    static class OutputWriter {
        private final PrintWriter writer;

        public OutputWriter(OutputStream outputStream) {
            writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
        }

        public OutputWriter(Writer writer) {
            this.writer = new PrintWriter(writer);
        }

        public void close() {
            writer.close();
        }

        public void printLine(long i) {
            writer.println(i);
        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private InputReader.SpaceCharFilter filter;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1) {
                throw new InputMismatchException();
            }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }

        public int readInt() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public boolean isSpaceChar(int c) {
            if (filter != null) {
                return filter.isSpaceChar(c);
            }
            return isWhitespace(c);
        }

        public static boolean isWhitespace(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }
}