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;
using namespace chrono;
const int infinity = (int)1e9 + 42;
const int64_t llInfinity = (int64_t)1e18 + 256;
const int module = (int)1e9 + 7;
const long double eps = 1e-8;
mt19937_64 randGen(system_clock().now().time_since_epoch().count());
inline void raiseError(string errorCode) {
  cerr << "Error : " << errorCode << endl;
  exit(42);
}
struct Treap {
  int x, y;
  int size;
  int64_t sum;
  Treap *l, *r;
  Treap(int x) : x(x), y(randGen()), size(1), sum(x), l(nullptr), r(nullptr) {}
  ~Treap() {
    if (l != nullptr) {
      delete l;
    }
    if (r != nullptr) {
      delete r;
    }
  }
};
typedef Treap* pTreap;
inline int getSize(pTreap t) { return (t != nullptr) ? t->size : 0; }
inline int64_t getSum(pTreap t) { return (t != nullptr) ? t->sum : 0; }
inline void update(pTreap t) {
  if (t != nullptr) {
    t->size = getSize(t->l) + 1 + getSize(t->r);
    t->sum = getSum(t->l) + t->x + getSum(t->r);
  }
}
inline void split(pTreap t, pTreap& l, pTreap& r, int x) {
  if (t == nullptr) {
    l = r = nullptr;
  } else if (x <= t->x) {
    split(t->l, l, t->l, x);
    r = t;
  } else {
    split(t->r, t->r, r, x);
    l = t;
  }
  update(l);
  update(r);
}
inline void splitSize(pTreap t, pTreap& l, pTreap& r, int count) {
  if (t == nullptr) {
    l = r = nullptr;
  } else if (count <= getSize(t->l)) {
    splitSize(t->l, l, t->l, count);
    r = t;
  } else {
    splitSize(t->r, t->r, r, count - getSize(t->l) - 1);
    l = t;
  }
  update(l);
  update(r);
}
void merge(pTreap& t, pTreap l, pTreap r) {
  if (l == nullptr || r == nullptr) {
    t = (l != nullptr) ? l : r;
  } else if (l->y > r->y) {
    merge(l->r, l->r, r);
    t = l;
  } else {
    merge(r->l, l, r->l);
    t = r;
  }
  update(t);
}
inline void insert(pTreap& t, pTreap it) {
  if (t == nullptr) {
    t = it;
  } else if (it->y > t->y) {
    split(t, it->l, it->r, it->x);
    t = it;
  } else if (it->x <= t->x) {
    insert(t->l, it);
  } else {
    insert(t->r, it);
  }
  update(t);
}
inline void erase(pTreap& t, int x) {
  if (t != nullptr) {
    if (x == t->x) {
      pTreap oldT = t;
      merge(t, t->l, t->r);
      oldT->l = oldT->r = nullptr;
      delete oldT;
    } else if (x < t->x) {
      erase(t->l, x);
    } else {
      erase(t->r, x);
    }
  }
  update(t);
}
inline void unite(pTreap& t, pTreap l, pTreap r) {
  if (l == nullptr || r == nullptr) {
    t = (l != nullptr) ? l : r;
  } else {
    if (r->y > l->y) {
      swap(l, r);
    }
    pTreap rl, rr;
    split(r, rl, rr, l->x);
    unite(l->l, l->l, rl);
    unite(l->r, l->r, rr);
    t = l;
  }
  update(t);
}
void outItem(pTreap t) { cout << t->x << " "; }
void out(pTreap t) {
  if (t != nullptr) {
    out(t->l);
    outItem(t);
    out(t->r);
  }
}
pTreap nthElement(pTreap t, int n) {
  if (t == nullptr) {
    return nullptr;
  } else if (n == getSize(t->l)) {
    return t;
  } else if (n < getSize(t->l)) {
    return nthElement(t->l, n);
  } else {
    return nthElement(t->r, n - getSize(t->l) - 1);
  }
}
pTreap find(pTreap t, int x) {
  if (t == nullptr) {
    return nullptr;
  } else if (x == t->x) {
    return t;
  } else if (x < t->x) {
    return find(t->l, x);
  } else {
    return find(t->r, x);
  }
}
signed main() {
  ios_base::sync_with_stdio(false);
  int64_t n, m;
  cin >> n >> m;
  vector<int64_t> l(n);
  for (int64_t i = 1; i < n; i++) {
    cin >> l[i];
  }
  vector<pair<int64_t, int64_t> > q(m);
  for (int64_t i = 0; i < m; i++) {
    cin >> q[i].first >> q[i].second;
    q[i].first--;
  }
  vector<vector<pair<int64_t, int64_t> > > sumByLen(n);
  for (int64_t i = 0; i < m; i++) {
    int64_t v = q[i].first;
    int64_t rng = q[i].second;
    int64_t len = 0;
    sumByLen[v].emplace_back(rng, -1);
    while (v != 0) {
      int64_t p = (v - 1) / 2;
      len += l[v];
      int64_t pL = p * 2 + 1, pR = p * 2 + 2;
      int64_t q = -1;
      if (pL < n && pL != v) {
        q = pL;
      } else if (pR < n && pR != v) {
        q = pR;
      }
      if (q >= 0) {
        sumByLen[q].emplace_back(rng - len - l[q], -1);
      }
      v = p;
    }
  }
  for (int64_t i = 0; i < n; i++) {
    sort(sumByLen[i].begin(), sumByLen[i].end());
  }
  function<pTreap(int64_t, int64_t)> dfs = [&](int64_t v, int64_t fUp) {
    pTreap p = new Treap(fUp);
    for (int64_t i = 1; i <= 2; i++) {
      if (v * 2 + i < n) {
        pTreap add = dfs(v * 2 + i, fUp + l[v * 2 + i]);
        unite(p, p, add);
      }
    }
    vector<pTreap> pieces;
    pieces.reserve(sumByLen[v].size());
    int64_t cumSize = 0, cumSum = 0;
    for (auto& it : sumByLen[v]) {
      int64_t val = it.first + fUp;
      int64_t& res = it.second;
      pieces.push_back(nullptr);
      split(p, pieces.back(), p, val);
      cumSize += getSize(pieces.back());
      cumSum += getSum(pieces.back());
      res = (int64_t)val * cumSize - cumSum;
    }
    pTreap q = nullptr;
    for (auto it : pieces) {
      merge(q, q, it);
    }
    merge(q, q, p);
    return q;
  };
  dfs(0, 0);
  vector<int64_t> answers(m);
  for (int64_t i = 0; i < m; i++) {
    int64_t v = q[i].first;
    int64_t rng = q[i].second;
    int64_t len = 0;
    answers[i] += lower_bound(sumByLen[v].begin(), sumByLen[v].end(),
                              make_pair(rng, (int64_t)-1))
                      ->second;
    while (v != 0) {
      int64_t p = (v - 1) / 2;
      len += l[v];
      if (rng >= len) {
        answers[i] += rng - len;
      }
      int64_t pL = p * 2 + 1, pR = p * 2 + 2;
      int64_t q = -1;
      if (pL < n && pL != v) {
        q = pL;
      } else if (pR < n && pR != v) {
        q = pR;
      }
      if (q >= 0) {
        answers[i] += lower_bound(sumByLen[q].begin(), sumByLen[q].end(),
                                  make_pair(rng - len - l[q], (int64_t)-1))
                          ->second;
      }
      v = p;
    }
    cout << answers[i] << endl;
  }
  return 0;
}