#include <bits/stdc++.h>
using namespace std;
const int N = (1 << 20) + 7;
int n;
int a[N], tmp[N];
long long p[22], q[22];
void dfs(int l, int r, int dep) {
  if (l == r) {
    scanf("%d", &a[l]);
    return;
  }
  int m = (l + r) >> 1;
  dfs(l, m, dep - 1);
  dfs(m + 1, r, dep - 1);
  int i, x = m + 1, y = m + 1;
  for (i = l; i <= m; i++) {
    while (x <= r && a[x] < a[i]) x++;
    while (y <= r && a[y] <= a[i]) y++;
    p[dep] += x - m - 1;
    q[dep] += r - y + 1;
  }
  x = l, y = m;
  int u = m + 1, v = r, id = l;
  while (x <= y && u <= v) {
    if (a[x] <= a[u])
      tmp[id++] = a[x++];
    else
      tmp[id++] = a[u++];
  }
  while (x <= y) tmp[id++] = a[x++];
  while (u <= v) tmp[id++] = a[u++];
  for (i = l; i <= r; i++) a[i] = tmp[i];
}
int m;
vector<int> b;
int main() {
  int i;
  scanf("%d", &n);
  dfs(1, 1 << n, n);
  scanf("%d", &m);
  while (m--) {
    int x;
    scanf("%d", &x);
    for (i = x; i >= 1; i--) swap(p[i], q[i]);
    long long ans = 0;
    for (i = n; i >= 1; i--) ans += p[i];
    printf("%lld\n", ans);
  }
  return 0;
}
