#include <bits/stdc++.h>
using namespace std;
int a[(1 << 20) + 10];
int b[(1 << 20) + 10];
int temp[(1 << 20) + 10];
int pos[30] = {0};
long long shun[30] = {0};
long long ni[30] = {0};
void merge(int s, int t, int l) {
  if (s != t) {
    merge(s, (s + t) / 2, l + 1);
    merge((s + t) / 2 + 1, t, l + 1);
  }
  int i = s, j = (s + t) / 2 + 1;
  int tot = 0;
  while (i <= (s + t) / 2 || j <= t) {
    if (i > (s + t) / 2) {
      j++;
    } else if (j > t) {
      i++;
    } else {
      if (b[i] <= b[j])
        i++;
      else {
        ni[l] += ((s + t) / 2 - i + 1);
        j++;
      }
    }
  }
  i = s, j = (s + t) / 2 + 1;
  tot = 0;
  while (i <= (s + t) / 2 || j <= t) {
    if (i > (s + t) / 2) {
      temp[tot++] = b[j];
      j++;
    } else if (j > t) {
      temp[tot++] = b[i];
      i++;
    } else {
      if (b[j] <= b[i]) {
        temp[tot++] = b[j];
        j++;
      } else {
        temp[tot++] = b[i];
        shun[l] += (t - j + 1);
        i++;
      }
    }
  }
  for (int i = s; i <= t; i++) {
    b[i] = temp[i - s];
  }
}
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < (1 << n); i++) {
    scanf("%d", &a[i]);
    b[i] = a[i];
  }
  int N = (1 << n);
  merge(0, N - 1, 1);
  int m;
  scanf("%d", &m);
  for (int i = 0; i < m; i++) {
    int q;
    scanf("%d", &q);
    for (int j = n - q + 1; j <= n; j++) pos[j] = 1 - pos[j];
    long long res = 0;
    for (int j = 1; j <= n; j++) {
      if (pos[j] == 1)
        res += shun[j];
      else
        res += ni[j];
    }
    cout << res << endl;
  }
}
