#include <bits/stdc++.h>
using namespace std;
int A[(1 << 20) + 1];
long long Cnt[25][2];
void MergeSort(int L, int R, int dep) {
  if (L == R) return;
  int mid = (L + R) >> 1;
  MergeSort(L, mid, dep - 1), MergeSort(mid + 1, R, dep - 1);
  for (int i = (L), i_ = (mid); i <= i_; i++) {
    int pos = lower_bound(A + mid + 1, A + R + 1, A[i]) - A - 1;
    if (A[pos] < A[i]) Cnt[dep][0] += pos - mid;
    pos = upper_bound(A + mid + 1, A + R + 1, A[i]) - A;
    if (A[pos] > A[i]) Cnt[dep][1] += R - pos + 1;
  }
  sort(A + L, A + R + 1);
}
int main() {
  int n, m, a;
  scanf("%d", &n);
  for (int i = (1), i_ = (1 << n); i <= i_; i++) scanf("%d", &A[i]);
  MergeSort(1, 1 << n, n);
  scanf("%d", &m);
  for (int i = (1), i_ = (m); i <= i_; i++) {
    long long ans = 0;
    scanf("%d", &a);
    for (int j = (0), j_ = (a); j <= j_; j++) swap(Cnt[j][0], Cnt[j][1]);
    for (int j = (0), j_ = (n); j <= j_; j++) ans += Cnt[j][0];
    printf("%lld\n", ans);
  }
  return 0;
}
