#include <bits/stdc++.h>
using namespace std;
int N, NN, Q;
int a[2400005];
int L[2400005], R[2400005];
long long t[2400005], s[2400005], cnt[2400005];
void merge(int l, int r, int lv) {
  int mid = (l + r) / 2;
  for (int i = l; i <= mid; i++) L[i] = a[i];
  for (int i = mid + 1; i <= r; i++) R[i] = a[i];
  int i = l, j = mid + 1, k = l;
  while (i <= mid || j <= r) {
    if (j > r || i <= mid && L[i] <= R[j]) {
      if (i <= mid && L[i] == R[j]) s[lv]++;
      a[k++] = L[i++];
    } else {
      cnt[lv] += mid - i + 1;
      a[k++] = R[j++];
    }
  }
  return;
}
void Msort(int l, int r, int lv) {
  if (l == r) return;
  int mid = (l + r) / 2;
  Msort(l, mid, lv - 1);
  Msort(mid + 1, r, lv - 1);
  merge(l, r, lv);
}
int main() {
  scanf("%d", &N);
  NN = (1 << N);
  for (int i = 1; i <= NN; i++) {
    scanf("%d", &a[i]);
  }
  Msort(1, NN, N);
  for (int i = 1; i <= N; i++) {
    long long m = 1 << i;
    t[i] = (m * m / 4) * (1 << (N - i)) - s[i];
  }
  scanf("%d", &Q);
  int q;
  while (Q--) {
    scanf("%d", &q);
    for (int i = 1; i <= q; i++) {
      cnt[i] = t[i] - cnt[i];
    }
    long long ans = 0;
    for (int i = 1; i <= N; i++) ans += cnt[i];
    printf("%lld\n", ans);
  }
  return 0;
}
