#include <bits/stdc++.h>
using namespace std;
const int maxn = (1 << 20) + 50;
int n, a[maxn], N, b[maxn];
long long same[30], inv[30], all[30];
struct ar_tree {
  long long c[maxn];
  void add(int x, int k) {
    for (; x <= N; x += x & -x) c[x] += k;
  }
  long long query(int x) {
    long long res(0);
    for (; x; x -= x & -x) res += c[x];
    return res;
  }
} T;
void solve(int l, int r, int dep) {
  if (l == r) return;
  int mid = (l + r) >> 1;
  solve(l, mid, dep + 1);
  solve(mid + 1, r, dep + 1);
  for (int i = mid + 1; i <= r; ++i) T.add(a[i], 1);
  all[dep] += (long long)(mid - l + 1) * (r - mid);
  for (int i = l; i <= mid; ++i)
    inv[dep] += T.query(a[i] - 1),
        same[dep] += T.query(a[i]) - T.query(a[i] - 1);
  for (int i = mid + 1; i <= r; ++i) T.add(a[i], -1);
}
int main() {
  scanf("%d", &n);
  N = 1 << n;
  for (int i = 1; i <= N; ++i) scanf("%d", &a[i]), b[i] = a[i];
  sort(b + 1, b + 1 + N);
  int m = unique(b + 1, b + 1 + N) - (b + 1);
  for (int i = 1; i <= N; ++i) a[i] = lower_bound(b + 1, b + 1 + m, a[i]) - b;
  solve(1, N, 0);
  int Q;
  for (scanf("%d", &Q); Q--;) {
    int t;
    scanf("%d", &t);
    t = n - t;
    for (int i = t; i <= n; ++i) inv[i] = all[i] - inv[i] - same[i];
    long long res(0);
    for (int i = 0; i <= n; ++i) res += inv[i];
    printf("%I64d\n", res);
  }
  return 0;
}
