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 CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
vector<vector<long long> > arr, pre;
vector<int> l;
int n, m;
void gen(int loc) {
  if (loc > n) return;
  arr[loc].push_back(0);
  pre[loc].push_back(0);
  int lc = 2 * loc, rc = 2 * loc + 1, l1, r1;
  if (lc <= n) gen(lc);
  if (rc <= n) gen(rc);
  int i = 0, j = 0;
  while (i < arr[lc].size() && j < arr[rc].size()) {
    if ((arr[lc][i] + l[lc]) < (arr[rc][j] + l[rc])) {
      arr[loc].push_back(arr[lc][i] + l[lc]);
      pre[loc].push_back(arr[lc][i] + l[lc]);
      pre[loc][pre[loc].size() - 1] += pre[loc][pre[loc].size() - 2];
      i++;
    } else {
      arr[loc].push_back(arr[rc][j] + l[rc]);
      pre[loc].push_back(arr[rc][j] + l[rc]);
      pre[loc][pre[loc].size() - 1] += pre[loc][pre[loc].size() - 2];
      j++;
    }
  }
  while (i < arr[lc].size()) {
    arr[loc].push_back(arr[lc][i] + l[lc]);
    pre[loc].push_back(arr[lc][i] + l[lc]);
    pre[loc][pre[loc].size() - 1] += pre[loc][pre[loc].size() - 2];
    i++;
  }
  while (j < arr[rc].size()) {
    arr[loc].push_back(arr[rc][j] + l[rc]);
    pre[loc].push_back(arr[rc][j] + l[rc]);
    pre[loc][pre[loc].size() - 1] += pre[loc][pre[loc].size() - 2];
    j++;
  }
}
long long solve(long long idx, long long h) {
  long long ans = 0, len = upper_bound(arr[idx].begin(), arr[idx].end(), h) -
                           arr[idx].begin();
  ans += h * len - pre[idx][len - 1];
  h -= l[idx];
  int prev = idx;
  idx /= 2;
  while ((idx) && h > 0) {
    ans += h;
    if (2 * idx == prev) {
      int ch = 2 * idx + 1;
      if (ch <= n && h > l[ch]) {
        len = upper_bound(arr[ch].begin(), arr[ch].end(), h - l[ch]) -
              arr[ch].begin();
        ans += (h - l[ch]) * len - pre[ch][len - 1];
      }
    } else {
      int ch = 2 * idx;
      if (ch <= n && h > l[ch]) {
        len = upper_bound(arr[ch].begin(), arr[ch].end(), h - l[ch]) -
              arr[ch].begin();
        ans += (h - l[ch]) * len - pre[ch][len - 1];
      }
    }
    h -= l[idx];
    prev = idx;
    idx /= 2;
  }
  return ans;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> m;
  l.resize(2 * n + 10);
  arr.resize(2 * n + 10);
  pre.resize(2 * n + 10);
  for (int i = 2; i <= n; i++) {
    cin >> l[i];
  }
  gen(1);
  int x, h;
  for (int i = 0; i < m; i++) {
    cin >> x >> h;
    cout << solve(x, h) << '\n';
  }
  return 0;
}