#include <bits/stdc++.h>
using namespace std;
const int lg = 21;
long long a[(1 << lg) + 9], ans[1 << lg], ans2[1 << lg], tmp[(1 << lg) + 9], n,
    q, x, t;
void ms(int s = 0, int e = (1 << n), int h = 0) {
  if (e - s == 1) return;
  long long mid = s + e >> 1, ret = 0, ret2 = 0;
  ms(s, mid, h + 1), ms(mid, e, h + 1);
  for (int i = s; i < mid; i++) {
    ret2 += e - mid - (upper_bound(a + mid, a + e, a[i]) - a - mid);
    ret += lower_bound(a + mid, a + e, a[i]) - a - mid;
  }
  sort(a + s, a + e);
  ans[h] += ret, ans2[h] += ret2;
}
int main() {
  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  cin >> n;
  for (int i = 0; i < (1 << n); i++) cin >> a[i];
  ms(), cin >> q;
  while (q--) {
    long long ret = 0;
    cin >> x;
    for (int i = n - x; i <= n; i++) swap(ans[i], ans2[i]);
    for (int i = 0; i <= n; i++) ret += ans[i];
    cout << ret << '\n';
  }
}
