#include <bits/stdc++.h>
using namespace std;
int n, m;
int a[2000222];
long long lay[33];
long long eq[33];
long long ans = 0;
int main() {
  cin >> n;
  for (int i = 0; i < (1ll << (n)); i++) scanf("%d", &a[i]);
  for (int i = 0; i < n; i++) {
    int x = (1ll << (i));
    for (int j = 0; j < (1ll << (n)); j += x) {
      sort(a + j, a + j + x);
    }
    for (int j = 0; j < (1ll << (n)); j += 2 * x) {
      for (int k = j; k < j + x; k++) {
        int u = lower_bound(a + j + x, a + j + x + x, a[k]) - a;
        lay[i + 1] += u - (j + x);
        int uu = upper_bound(a + j + x, a + j + x + x, a[k]) - a;
        eq[i + 1] += uu - u;
      }
    }
    ans += lay[i + 1];
  }
  cin >> m;
  for (int i = 0; i < m; i++) {
    int x;
    scanf("%d", &x);
    if (x == 0) {
      printf("%I64d\n", ans);
      continue;
    }
    for (int w = 1; w <= x; w++) {
      long long g = (1ll << (w - 1));
      g = g * g;
      g *= (1ll << (n - w));
      ans -= lay[w];
      lay[w] = g - lay[w] - eq[w];
      ans += lay[w];
    }
    printf("%I64d\n", ans);
  }
  return 0;
}
