#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e18;
const int MAXN = 2e6 + 105;
const int N = 5000 + 15;
const double EPS = 1e-9;
int dx[] = {1, 0, 0, -1};
int dy[] = {0, 1, -1, 0};
long long i, j, k, n, m;
long long a[MAXN];
long long lvl[50], reverseLvl[50];
void calc(long long left, long long right, long long level) {
  if (left == right) return;
  long long mid = (left + right) / 2;
  calc(left, mid, level - 1);
  calc(mid + 1, right, level - 1);
  for (int i = left; i <= mid; i++) {
    long long greaterThan =
        lower_bound(a + mid + 1, a + right + 1, a[i]) - (a + mid + 1);
    lvl[level] += greaterThan;
    long long tmp =
        upper_bound(a + mid + 1, a + right + 1, a[i]) - (a + mid + 1);
    reverseLvl[level] += right - mid - tmp;
  }
  sort(a + left, a + right + 1);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  long long len = 1 << n;
  for (int i = 1; i <= len; i++) cin >> a[i];
  calc(1, len, n);
  int t;
  cin >> t;
  while (t--) {
    int q;
    cin >> q;
    long long ans = 0;
    for (int i = 1; i <= q; i++) {
      swap(lvl[i], reverseLvl[i]);
    }
    for (int i = 1; i <= n; i++) ans += lvl[i];
    cout << ans << '\n';
  }
  return 0;
}
