#include <bits/stdc++.h>
using namespace std;
long long int a[1 << 21];
pair<long long int, long long int> h[22 + 1];
long long int b[1 << 21];
void merge(long long int l, long long int r, long long int rt) {
  long long int mid = (l + r) / 2;
  long long int lo = l;
  long long int hi = mid + 1;
  long long int ans1 = 0;
  long long int ans = 0;
  long long int k = lo;
  long long int t = mid + 1;
  while (lo <= mid && hi <= r) {
    if (a[lo] <= a[hi]) {
      while (t <= r && a[lo] >= a[t]) t++;
      ans1 = ans1 + r - t + 1;
      b[k++] = a[lo++];
    } else if (a[lo] > a[hi]) {
      b[k++] = a[hi++];
      ans = ans + mid - lo + 1;
    }
  }
  while (lo <= mid) {
    b[k++] = a[lo++];
  }
  while (hi <= r) {
    b[k++] = a[hi++];
  }
  for (int i = l; i <= r; i++) a[i] = b[i];
  h[rt].first += ans;
  h[rt].second += ans1;
}
void ms(long long int l, long long int r, long long int rt) {
  if (l < r) {
    long long int mid = (l + r) / 2;
    ms(l, mid, rt - 1);
    ms(mid + 1, r, rt - 1);
    merge(l, r, rt);
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  long long int n;
  cin >> n;
  for (int i = 1; i <= (1LL << n); i++) cin >> a[i];
  long long int t = (1LL << n);
  for (int j = 1; j <= n; j++) {
    h[j] = make_pair(0, 0);
  }
  ms(1, t, n);
  long long int e, q, temp;
  cin >> e;
  while (e--) {
    cin >> q;
    for (int j = q; j >= 1; j--) {
      swap(h[j].first, h[j].second);
    }
    long long int ans = 0;
    for (int j = 1; j <= n; j++) {
      ans += h[j].first;
    }
    cout << ans << "\n";
  }
}
