The Smart Beaver from ABBYY began to develop a new educational game for children. The rules of the game are fairly simple and are described below.

The playing field is a sequence of n non-negative integers ai numbered from 1 to n. The goal of the game is to make numbers a1, a2, ..., ak (i.e. some prefix of the sequence) equal to zero for some fixed k (k < n), and this should be done in the smallest possible number of moves.

One move is choosing an integer i (1 ≤ i ≤ n) such that ai > 0 and an integer t (t ≥ 0) such that i + 2t ≤ n. After the values of i and t have been selected, the value of ai is decreased by 1, and the value of ai + 2t is increased by 1. For example, let n = 4 and a = (1, 0, 1, 2), then it is possible to make move i = 3, t = 0 and get a = (1, 0, 0, 3) or to make move i = 1, t = 1 and get a = (0, 0, 2, 2) (the only possible other move is i = 1, t = 0).

You are given n and the initial sequence ai. The task is to calculate the minimum number of moves needed to make the first k elements of the original sequence equal to zero for each possible k (1 ≤ k < n).

Input

The first input line contains a single integer n. The second line contains n integers ai (0 ≤ ai ≤ 104), separated by single spaces.

The input limitations for getting 20 points are: 

  * 1 ≤ n ≤ 300



The input limitations for getting 50 points are: 

  * 1 ≤ n ≤ 2000



The input limitations for getting 100 points are: 

  * 1 ≤ n ≤ 105

Output

Print exactly n - 1 lines: the k-th output line must contain the minimum number of moves needed to make the first k elements of the original sequence ai equal to zero.

Please do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams, or the %I64d specifier.

Examples

Input

4
1 0 1 2


Output

1
1
3


Input

8
1 2 3 4 5 6 7 8


Output

1
3
6
10
16
24
40
#include <bits/stdc++.h>
using namespace std;
const int N = 100000;
vector<int> graph[N];
set<pair<int, int> > bridges;
int n, m, k, a, b, source[N], target[N];
int ND[N], L[N], H[N];
bool visited[N];
vector<int> children[N];
int order[N];
int comp[N], comp_cnt;
vector<int> tree[N];
int parent[N][30];
int tparent[N];
void addBridge(int a, int b) {
  if (a > b) {
    swap(a, b);
  }
  bridges.insert(pair<int, int>(a, b));
}
bool isBridge(int a, int b) {
  if (a > b) {
    swap(a, b);
  }
  return bridges.count(pair<int, int>(a, b));
}
void dfs(int i) {
  stack<int> st;
  st.push(i);
  while (!st.empty()) {
    int s = st.top();
    st.pop();
    if (comp[s] == -1) {
      comp[s] = comp_cnt;
      for (vector<int>::iterator it = graph[s].begin(); it != graph[s].end();
           it++) {
        if (!isBridge(s, *it)) st.push(*it);
      }
    }
  }
}
void findComponents() {
  memset(comp, -1, sizeof comp);
  comp_cnt = 0;
  for (int i = 0; i < n; i++) {
    if (comp[i] == -1) {
      dfs(i);
    }
    comp_cnt++;
  }
  for (int i = 0; i < n; i++) {
    for (vector<int>::iterator it = graph[i].begin(); it != graph[i].end();
         it++) {
      if (isBridge(i, *it)) {
        tree[comp[i]].push_back(comp[*it]);
      }
    }
  }
}
void buildLCA() {
  memset(parent, -1, sizeof parent);
  queue<int> q;
  q.push(0);
  L[0] = 0;
  while (!q.empty()) {
    int s = q.front();
    q.pop();
    for (vector<int>::iterator it = tree[s].begin(); it != tree[s].end();
         it++) {
      if (*it != parent[s][0]) {
        parent[*it][0] = s;
        L[*it] = L[s] + 1;
        q.push(*it);
      }
    }
  }
  for (int j = 1; 1 << j < n; j++)
    for (int i = 0; i < n; i++)
      if (parent[i][j - 1] != -1)
        parent[i][j] = parent[parent[i][j - 1]][j - 1];
}
int query(int p, int q) {
  int tmp, log, i;
  if (L[p] < L[q]) tmp = p, p = q, q = tmp;
  for (log = 1; 1 << log <= L[p]; log++)
    ;
  log--;
  for (i = log; i >= 0; i--)
    if (L[p] - (1 << i) >= L[q]) p = parent[p][i];
  if (p == q) return p;
  for (i = log; i >= 0; i--)
    if (parent[p][i] != -1 && parent[p][i] != parent[q][i])
      p = parent[p][i], q = parent[q][i];
  return parent[p][0];
}
void answerQueries() {
  for (int i = 0; i < k; i++) {
    int p = comp[source[i]], q = comp[target[i]];
    int lca = query(p, q);
    int result = L[p] + L[q] - 2 * lca;
    cout << result << endl;
  }
}
void findBridges() {
  vector<int> tree(n);
  memset(visited, 0, sizeof visited);
  stack<int> st, stp;
  st.push(0);
  stp.push(-1);
  for (int i = 0; !st.empty();) {
    int s = st.top();
    st.pop();
    int sp = stp.top();
    stp.pop();
    if (visited[s]) continue;
    visited[s] = true;
    tparent[s] = sp;
    order[s] = i;
    tree[order[s]] = s;
    if (sp != -1) children[sp].push_back(s);
    for (vector<int>::iterator it = graph[s].begin(); it != graph[s].end();
         it++) {
      st.push(*it);
      stp.push(s);
    }
    i++;
  }
  for (int i = n - 1; i >= 0; i--) {
    L[i] = i;
    int u = tree[i];
    for (vector<int>::iterator it = children[u].begin();
         it != children[u].end(); it++) {
      int v = order[*it];
      L[i] = min(L[i], L[v]);
    }
    for (vector<int>::iterator it = graph[u].begin(); it != graph[u].end();
         it++) {
      if (tparent[tree[i]] != *it) {
        L[i] = min(L[i], order[*it]);
      }
    }
    for (vector<int>::iterator it = children[u].begin();
         it != children[u].end(); it++) {
      int v = order[*it];
      if (L[v] == v) {
        addBridge(tree[v], tree[i]);
      }
    }
  }
}
void readInput() {
  scanf("%d %d", &n, &m);
  for (int i = 0; i < m; i++) {
    scanf("%d %d", &a, &b);
    a--;
    b--;
    graph[a].push_back(b);
    graph[b].push_back(a);
  }
  scanf("%d", &k);
  for (int i = 0; i < k; i++) {
    scanf("%d %d", &source[i], &target[i]);
    source[i]--;
    target[i]--;
  }
}
int main() {
  readInput();
  findBridges();
  findComponents();
  buildLCA();
  answerQueries();
  return 0;
}
