#include <bits/stdc++.h>
using namespace std;
const int sz = 2e5 + 10;
const int mod = 100000007;
int n, q, d;
long long a[22], b[22];
int ar[1 << 22];
vector<int> tree[1 << 22];
void build(int node, int ll, int rr, int dep = 0) {
  tree[node].clear();
  if (ll == rr) {
    tree[node].push_back(ar[ll]);
    a[dep] = b[dep] = 0;
    return;
  }
  int mid = (ll + rr) / 2;
  build(node * 2, ll, mid, dep + 1);
  build(node * 2 + 1, mid + 1, rr, dep + 1);
  vector<int>& left = tree[node * 2];
  vector<int>& right = tree[node * 2 + 1];
  vector<int>& result = tree[node];
  long long inv = 0, rev_inv = 0;
  int l = 0, r = 0, n = left.size(), m = right.size();
  while (l < n && r < m) {
    long long cnt_l = 0, cnt_r = 0;
    int x = min(left[l], right[r]);
    while (l < n && left[l] == x) l++, cnt_l++;
    while (r < m && right[r] == x) r++, cnt_r++;
    inv += cnt_r * (n - l);
    rev_inv += cnt_l * (m - r);
    cnt_l += cnt_r;
    while (cnt_l--) result.push_back(x);
  }
  while (l < n) result.push_back(left[l++]);
  while (r < m) result.push_back(right[r++]);
  a[dep] += inv;
  b[dep] += rev_inv;
}
int main() {
  while (cin >> n) {
    for (int i = 0; i < (1 << n); i++) scanf("%d", &ar[i]);
    memset(a, 0, sizeof a);
    memset(b, 0, sizeof b);
    build(1, 0, (1 << n) - 1);
    scanf("%d", &q);
    while (q--) {
      scanf("%d", &d);
      for (int i = n; i >= n - d; i--) {
        swap(a[i], b[i]);
      }
      long long ans = 0;
      for (int i = 0; i <= n; i++) {
        ans += a[i];
      }
      printf("%lld\n", ans);
    }
    cerr << "----\n";
  }
  return 0;
}
