#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e6 + 9;
int a[maxn];
long long int sum[30];
long long int allsum[30];
void merge(int l, int r, int deep) {
  if (deep == 0) return;
  int mid = l + r >> 1;
  merge(l, mid, deep - 1);
  merge(mid + 1, r, deep - 1);
  for (int i = mid + 1; i <= r; i++) {
    allsum[deep] += lower_bound(a + l, a + mid + 1, a[i]) - a - l;
    sum[deep] += mid + 1 - (upper_bound(a + l, a + mid + 1, a[i]) - a);
    allsum[deep] += mid + 1 - (upper_bound(a + l, a + mid + 1, a[i]) - a);
  }
  sort(a + l, a + r + 1);
}
int main() {
  int n;
  scanf("%d", &n);
  int all = 1 << n;
  for (int i = 1; i <= all; i++) {
    scanf("%d", &a[i]);
  }
  merge(1, all, n);
  int m;
  scanf("%d", &m);
  long long int ans = 0;
  for (int i = 0; i < 30; i++) {
    ans += sum[i];
  }
  while (m--) {
    int t;
    scanf("%d", &t);
    if (t == 0) {
      printf("%lld\n", ans);
    } else {
      for (int i = t; i >= 0; i--) {
        ans -= sum[i];
        sum[i] = (allsum[i] - sum[i]);
        ans += sum[i];
      }
      printf("%lld\n", ans);
    }
  }
  return 0;
}
