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>
const bool DEBUG = false;
using namespace std;
const long long maxn = 1e6 + 5;
const long long INF = 4e18;
const long long M = 1e9 + 7;
const int lg = 21;
int n, q, dp[maxn], p[maxn];
vector<long long> vec[maxn], pvec[maxn];
vector<pair<int, int> > g[maxn];
bool mark[maxn];
void dfs(int v, int t = -1) {
  p[v] = t;
  for (auto u : g[v])
    if (u.first != t) dp[u.first] = u.second, dfs(u.first, v);
  vec[v].push_back(0);
  pvec[v].push_back(0);
  if ((v << 1 | 1) <= n) {
    int x = v << 1, y = v << 1 | 1;
    int l1 = 0, l2 = 0;
    for (int i = 0; i < vec[x].size() + vec[y].size(); i++) {
      if (l1 == vec[x].size())
        vec[v].push_back(vec[y][l2] + dp[v << 1 | 1]), l2++;
      else if (l2 == vec[y].size())
        vec[v].push_back(vec[x][l1] + dp[v << 1]), l1++;
      else if (vec[x][l1] + dp[v << 1] < vec[y][l2] + dp[v << 1 | 1])
        vec[v].push_back(vec[x][l1] + dp[v << 1]), l1++;
      else
        vec[v].push_back(vec[y][l2] + dp[v << 1 | 1]), l2++;
      pvec[v].push_back(pvec[v][i] + vec[v][i + 1]);
    }
  } else if (v << 1 <= n) {
    for (int i = 0; i < vec[v << 1].size(); i++) {
      vec[v].push_back(vec[v << 1][i] + dp[v << 1]);
      pvec[v].push_back(pvec[v][i] + vec[v][i + 1]);
    }
  }
}
pair<long long, long long> f(long long x, vector<long long>(&v),
                             vector<long long>(&g)) {
  long long low = -1, high = v.size(), mid = 0;
  while (high - low > 1) {
    mid = (high + low) >> 1;
    if (v[mid] < x)
      low = mid;
    else
      high = mid;
  }
  if (low == -1) return {0, 0};
  return {low + 1, g[low]};
}
long long ans(long long v, long long x) {
  long long ans = 0, dis = 0, u = -1, dis1 = 0, t1 = 0, m1 = 0;
  vector<int> markshode;
  markshode.push_back(v);
  t1 = f(x, vec[v], pvec[v]).first;
  m1 = f(x, vec[v], pvec[v]).second;
  ans = t1 * x - m1;
  dis += dp[v], mark[v] = 1, v = p[v];
  while (v != -1 and dis < x) {
    ans = ans + x - dis;
    if ((v << 1 | 1) <= n) {
      int v1 = v << 1 | 1;
      int v2 = v << 1;
      if (mark[v1]) swap(v1, v2);
      t1 = f(x - dis - dp[v1], vec[v1], pvec[v1]).first;
      m1 = f(x - dis - dp[v1], vec[v1], pvec[v1]).second;
      ans = ans + x * t1 - m1 - t1 * (dp[v1] + dis);
    }
    dis += dp[v], mark[v] = 1, markshode.push_back(v), v = p[v];
  }
  for (auto u : markshode) mark[u] = 0;
  markshode.clear();
  return ans;
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n >> q;
  for (int i = 1; i < n; i++) {
    long long x;
    cin >> x;
    g[i + 1].push_back({(i + 1) / 2, x});
    g[(i + 1) / 2].push_back({i + 1, x});
  }
  dfs(1);
  for (int i = 0; i < q; i++) {
    long long v, x;
    cin >> v >> x;
    cout << ans(v, x) << "\n";
  }
  return 0;
}