#include <bits/stdc++.h>
using namespace std;
template <class T>
T abs(T x) {
  if (x < 0)
    return -x;
  else
    return x;
}
int N, tot, A[(1 << (20)) + 33];
long long smaller[23], bigger[23];
void Divide(int L, int R, int dep) {
  if (L == R) return;
  int M((L + R) >> 1);
  Divide(L, M, dep + 1);
  Divide(M + 1, R, dep + 1);
  for (int i(M + 1); i <= (R); ++i) {
    smaller[dep] += lower_bound(A + L, A + M + 1, A[i]) - 1 - (A + L - 1);
    bigger[dep] += A + M - (upper_bound(A + L, A + M + 1, A[i]) - 1);
  }
  sort(A + L, A + R + 1);
}
void solve() {
  scanf("%d", &N);
  tot = (1 << (N));
  for (int i(1); i <= (tot); ++i) scanf("%d", A + i);
  memset(smaller, 0, sizeof(smaller));
  memset(bigger, 0, sizeof(bigger));
  Divide(1, tot, 1);
  int M;
  scanf("%d", &M);
  long long ans = 0;
  for (int i(1); i <= (N); ++i) ans += bigger[i];
  while (M--) {
    int q;
    scanf("%d", &q);
    q = N - q + 1;
    for (int i(q); i <= (N); ++i) {
      ans -= bigger[i];
      swap(bigger[i], smaller[i]);
      ans += bigger[i];
    }
    printf("%I64d\n", ans);
  }
}
int main() {
  solve();
  return 0;
}
