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;
long long Set(long long n, long long pos) { return n = n | (1 << pos); }
long long reset(long long n, long long pos) { return n = n & ~(1 << pos); }
bool check(long long n, long long pos) { return (bool)(n & (1 << pos)); }
long long n, m;
long long nod, H;
long long par[3000005];
bool vis[3000005];
vector<long long> dis[3000005];
vector<long long> cumsum[3000005];
vector<pair<long long, long long> > graph[3000005];
vector<long long> visited_nodes;
void in_edges() {
  long long u, v, c;
  for (long long i = 1; i <= n - 1; i++) {
    u = (i + 1) / 2;
    v = i + 1;
    scanf("%lld", &c);
    graph[u].push_back(make_pair(v, c));
    par[v] = u;
  }
}
void preprocess(long long pos) {
  dis[pos].push_back(0);
  for (long long i = 0; i < graph[pos].size(); i++) {
    preprocess(graph[pos][i].first);
  }
  if (graph[pos].size() == 1) {
    long long adj = graph[pos][0].first;
    long long adj_cost = graph[pos][0].second;
    for (long long i = 0; i < dis[adj].size(); i++) {
      dis[pos].push_back(dis[adj][i] + adj_cost);
    }
  } else if (graph[pos].size() == 2) {
    long long adj1 = graph[pos][0].first;
    long long adj2 = graph[pos][1].first;
    long long adj1_cost = graph[pos][0].second;
    long long adj2_cost = graph[pos][1].second;
    long long i = 0;
    long long j = 0;
    while (i < dis[adj1].size() && j < dis[adj2].size()) {
      if (dis[adj1][i] + adj1_cost <= dis[adj2][j] + adj2_cost) {
        dis[pos].push_back(dis[adj1][i] + adj1_cost);
        i++;
      } else {
        dis[pos].push_back(dis[adj2][j] + adj2_cost);
        j++;
      }
    }
    while (i < dis[adj1].size()) {
      dis[pos].push_back(dis[adj1][i] + adj1_cost);
      i++;
    }
    while (j < dis[adj2].size()) {
      dis[pos].push_back(dis[adj2][j] + adj2_cost);
      j++;
    }
  }
}
void cumsum_make() {
  for (long long i = 1; i <= n; i++) {
    for (long long j = 0; j < dis[i].size(); j++) {
      if (j == 0) {
        cumsum[i].push_back(dis[i][j]);
      } else {
        cumsum[i].push_back(cumsum[i][j - 1] + dis[i][j]);
      }
    }
  }
}
long long binar(long long now_node, long long maxim) {
  long long low = 0;
  long long high = dis[now_node].size() - 1;
  long long mid;
  long long ans = -1;
  while (low <= high) {
    mid = (low + high) / 2;
    if (dis[now_node][mid] <= maxim) {
      ans = mid;
      low = mid + 1;
    } else {
      high = mid - 1;
    }
  }
  return ans;
}
long long solve(long long now_node, long long dis_cover, long long ager_node) {
  vis[now_node] = 1;
  visited_nodes.push_back(now_node);
  if (ager_node == -1) {
    long long index = binar(now_node, H - dis_cover);
    long long ans = 0;
    ans += (((index + 1) * H) -
            ((index + 1) * dis_cover + cumsum[now_node][index]));
    long long parent = par[now_node];
    if (vis[parent] == 0 && parent != 0) {
      long long par_to_now_cost;
      for (long long i = 0; i < graph[parent].size(); i++) {
        long long adj = graph[parent][i].first;
        if (adj == now_node) {
          par_to_now_cost = graph[parent][i].second;
        }
      }
      if (par_to_now_cost + dis_cover <= H) {
        return ans + solve(parent, par_to_now_cost + dis_cover, now_node);
      } else {
        return ans;
      }
    } else {
      return ans;
    }
  } else if (ager_node != -1) {
    long long ans = 0;
    ans += (H - dis_cover);
    for (long long i = 0; i < graph[now_node].size(); i++) {
      if (graph[now_node][i].first != ager_node) {
        if ((graph[now_node][i].second + dis_cover) <= H) {
          ans += solve(graph[now_node][i].first,
                       dis_cover + graph[now_node][i].second, -1);
        }
      }
    }
    long long parent = par[now_node];
    if (vis[parent] == 0 && parent != 0) {
      long long par_to_now_cost;
      for (long long i = 0; i < graph[parent].size(); i++) {
        long long adj = graph[parent][i].first;
        if (adj == now_node) {
          par_to_now_cost = graph[parent][i].second;
        }
      }
      if (par_to_now_cost + dis_cover <= H) {
        return ans + solve(parent, par_to_now_cost + dis_cover, now_node);
      } else {
        return ans;
      }
    } else {
      return ans;
    }
  }
}
int main() {
  scanf("%lld", &n);
  scanf("%lld", &m);
  in_edges();
  preprocess(1);
  cumsum_make();
  for (long long i = 1; i <= m; i++) {
    scanf("%lld", &nod);
    scanf("%lld", &H);
    long long ans = solve(nod, 0, -1);
    printf("%lld\n", ans);
    for (long long i = 0; i < visited_nodes.size(); i++) {
      vis[visited_nodes[i]] = 0;
    }
    visited_nodes.clear();
  }
  return 0;
}