#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
const int N = (1 << 20) + 8;
const int M = 26;
long long l[M], r[M];
int iCount[M], tree[N], data[N], hashv[N], sz;
inline int lowbit(int x) { return x & (-x); }
void Treeadd(int pos, int val) {
  for (; pos <= sz; pos += lowbit(pos)) tree[pos] += val;
}
int Getnum(int pos) {
  int ret = 0;
  for (; pos > 0; pos -= lowbit(pos)) ret += tree[pos];
  return ret;
}
void Dfs(int pos, int dep) {
  if (dep < 1) return;
  int mid = pos + (1 << (dep - 1)), bound = pos + (1 << dep);
  Dfs(pos, dep - 1);
  Dfs(mid, dep - 1);
  for (int i = pos; i < mid; i++) Treeadd(data[i], 1);
  for (int i = mid; i < bound; i++) {
    l[dep] += Getnum(data[i] - 1);
    r[dep] += mid - pos - Getnum(data[i]);
  }
  for (int i = pos; i < mid; i++) Treeadd(data[i], -1);
}
int main() {
  int n, m, q;
  scanf("%d", &n);
  int top = 1 << n;
  for (int i = 1; i <= top; i++) {
    scanf("%d", &data[i]);
    hashv[i] = data[i];
  }
  sort(hashv + 1, hashv + 1 + top);
  sz = unique(hashv + 1, hashv + 1 + top) - (hashv + 1);
  for (int i = 1; i <= top; i++)
    data[i] = lower_bound(hashv + 1, hashv + 1 + sz, data[i]) - hashv;
  Dfs(1, n);
  for (scanf("%d", &m); m > 0; m--) {
    scanf("%d", &q);
    for (int i = 1; i <= q; i++) iCount[i]++;
    long long ans = 0;
    for (int i = 1; i <= n; i++) {
      if (iCount[i] & 1)
        ans += l[i];
      else
        ans += r[i];
    }
    printf("%I64d\n", ans);
  }
  return 0;
}
