import static java.util.Arrays.*;
import static java.util.Collections.*;

import java.text.*;
import java.util.*;

public class C {

	public C () {
		int N = sc.nextInt(), Z = 1 << N;
		int [] A = new int [Z], B = new int [Z];
		for (int i = 0; i < Z; ++i)
			B[Z-1-i] = A[i] = sc.nextInt();

		long X = 0;

		long [] S = new long [N+1];
		for (int i = 1; i <= N; ++i)
			X += S[i] = calc(A, 1 << i);

		long [] T = new long [N+1];
		for (int i = 1; i <= N; ++i)
			T[i] = calc(B, 1 << i);

		int M = sc.nextInt();
		for (int i = 0; i < M; ++i) {
			int Q = sc.nextInt();
			for (int j = 1; j <= Q; ++j) {
				X += T[j] - S[j];
				S[j] += T[j]; T[j] = S[j] - T[j]; S[j] -= T[j];
			}
			IOUtils.pw.println(X);
		}
	}

	long calc(int [] A, int M) {
		int Z = A.length; long res = 0;
		for (int i = 0; i < Z/M; ++i) {
			Integer [] Q = new Integer [M];
			for (int j = 0; j < M; ++j)
				Q[j] = A[M*i + j];
			sort(Q, 0, M/2); int [] K = invert(si(Q)); int k = 0;
			for (int j = 0; j < M/2; ++j) {
				if (Q[j] > Q[k])
					k = j;
				res += K[k] - k;
			}
		}
		return res;
	}

	private static int [] invert(int [] J) {
		int N = J.length;
		int [] res = new int [N];
		for (int i = 0; i < N; ++i)
			res[J[i]] = i;
		return res;
	}
	private static <T extends Comparable<T>> int [] si(final T [] X) { return si(X, reverseOrder(reverseOrder())); }
	private static <T> int [] si(final T [] X, final Comparator<T> C) {
		int N = X.length;
		Integer [] res = new Integer [N];
		for (int i = 0; i < N; ++i)
			res[i] = i;
		sort(res, new Comparator<Integer>() {
			public int compare(Integer i, Integer j) {
				int res = C.compare(X[i], X[j]);
				return res != 0 ? res : i.compareTo(j);
			}
		});
		return toPrimitive(res);
	}
	private static Integer [] toObject(int ... A) { Integer [] res = new Integer [A.length]; for (int i = 0; i < A.length; ++i) res[i] = A[i]; return res; }
	private static int [] toPrimitive(Integer [] A) { int [] res = new int [A.length]; for (int i = 0; i < A.length; ++i) res[i] = A[i]; return res; }
	////////////////////////////////////////////////////////////////////////////////////
	private final static IOUtils.MyScanner sc = new IOUtils.MyScanner();
	private static void exit() { IOUtils.exit(); }
	private static class IOUtils {
		public static class MyScanner {
			public String next() { newLine(); return line[index++]; }
			public int nextInt() { return Integer.parseInt(next()); }
			//////////////////////////////////////////////
			private boolean eol() { return index == line.length; }
			private String readLine() {
				try {
					return r.readLine();
				} catch (Exception e) {
					throw new Error (e);
				}
			}
			private final java.io.BufferedReader r;
			private MyScanner () { this(new java.io.BufferedReader(new java.io.InputStreamReader(System.in))); }
			private MyScanner (java.io.BufferedReader r) {
				try {
					this.r = r;
					while (!r.ready())
						Thread.sleep(1);
					start();
				} catch (Exception e) {
					throw new Error(e);
				}
			}
			private String [] line;
			private int index;
			private void newLine() {
				if (line == null || eol()) {
					line = split(readLine());
					index = 0;
				}
			}
			private String [] split(String s) { return s.length() > 0 ? s.split(" ") : new String [0]; }
		}
		private static String build(Object o, Object... a) { return buildDelim(" ", o, a); }
		private static String buildDelim(String delim, Object o, Object... a) {
			StringBuilder b = new StringBuilder();
			append(b, o, delim);
			for (Object p : a)
				append(b, p, delim);
			return b.substring(delim.length());
		}
		//////////////////////////////////////////////////////////////////////////////////
		private static void start() { if (t == 0) t = millis(); }
		private static void append(StringBuilder b, Object o, String delim) {
			if (o.getClass().isArray()) {
				int len = java.lang.reflect.Array.getLength(o);
				for (int i = 0; i < len; ++i)
					append(b, java.lang.reflect.Array.get(o, i), delim);
			} else if (o instanceof Iterable<?>)
				for (Object p : (Iterable<?>) o)
					append(b, p, delim);
			else {
				if (o instanceof Double)
					o = new DecimalFormat("#.############").format(o);
				b.append(delim).append(o);
			}
		}
		private static java.io.PrintWriter pw = new java.io.PrintWriter(System.out);
		private static void err(Object o, Object ...a) { System.err.println(build(o, a)); }
		private static void exit() {
			IOUtils.pw.close();
			System.out.flush();
			err("------------------");
			err(IOUtils.time());
			System.exit(0);
		}
		private static long t;
		private static long millis() { return System.currentTimeMillis(); }
		private static String time() { return "Time: " + (millis() - t) / 1000.0; }
	}
	public static void main (String[] args) { new C(); exit(); }
}


import java.io.*;
import java.util.*;

public class CF {
    FastScanner in;
    PrintWriter out;

    long[] inv1, inv2;
    int[] tmp = new int[1 << 21];

    void go(int[] a, int l, int r, int h) {
        if (l == r) {
            return;
        } else {
            int m = (l + r) >> 1;
            m++;
            go(a, l, m - 1, h + 1);
            go(a, m, r, h + 1);
            {
                int it1 = l, it2 = m;
                int it = 0;
                while (it1 < m && it2 <= r) {
                    if (a[it1] <= a[it2]) {
                        tmp[it++] = a[it1++];
                        inv1[h] += (it2 - m);
                    } else {
                        tmp[it++] = a[it2++];
                    }
                }
                while (it1 < m) {
                    tmp[it++] = a[it1++];
                    inv1[h] += it2 - m;
                }
                while (it2 <= r) {
                    tmp[it++] = a[it2++];
                }
            }
            {
                int it1 = l, it2 = m;
                while (it1 < m && it2 <= r) {
                    if (a[it1] < a[it2]) {
                        it1++;
                    } else {
                        inv2[h] += (it1 - l);
                        it2++;
                    }
                }
                while (it2 <= r) {
                    inv2[h] += it1 - l;
                    it2++;
                }
            }
            for (int i = l; i <= r; i++) {
                a[i] = tmp[i - l];
            }
        }
    }

    void solve() {
        int n = in.nextInt();
        inv1 = new long[n];
        inv2 = new long[n];
        int len = 1 << n;
        int[] a = new int[len];
        for (int i = 0; i < len; i++)
            a[i] = in.nextInt();
        go(a, 0, len - 1, 0);
        int m = in.nextInt();
        boolean[] now = new boolean[n];
        long nowInv = 0;
        for (int i = 0; i < n; i++)
            nowInv += inv1[i];
        for (int i = 0; i < m; i++) {
            int q = in.nextInt();
            for (int j = 0; j < q; j++) {
                now[n - 1 - j] = !now[n - 1 - j];
                if (now[n - 1 - j]) {
                    nowInv += inv2[n - 1 - j] - inv1[n - 1 - j];
                } else {
                    nowInv += inv1[n - 1 - j] - inv2[n - 1 - j];
                }
            }
            out.println(nowInv);
        }
    }

    void run() {
        try {
            in = new FastScanner(new File("test.in"));
            out = new PrintWriter(new File("test.out"));

            solve();

            out.close();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
    }

    void runIO() {

        in = new FastScanner(System.in);
        out = new PrintWriter(System.out);

        solve();

        out.close();
    }

    class FastScanner {
        BufferedReader br;
        StringTokenizer st;

        public FastScanner(File f) {
            try {
                br = new BufferedReader(new FileReader(f));
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            }
        }

        public FastScanner(InputStream f) {
            br = new BufferedReader(new InputStreamReader(f));
        }

        String next() {
            while (st == null || !st.hasMoreTokens()) {
                String s = null;
                try {
                    s = br.readLine();
                } catch (IOException e) {
                    e.printStackTrace();
                }
                if (s == null)
                    return null;
                st = new StringTokenizer(s);
            }
            return st.nextToken();
        }

        boolean hasMoreTokens() {
            while (st == null || !st.hasMoreTokens()) {
                String s = null;
                try {
                    s = br.readLine();
                } catch (IOException e) {
                    e.printStackTrace();
                }
                if (s == null)
                    return false;
                st = new StringTokenizer(s);
            }
            return true;
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }
    }

    public static void main(String[] args) {
        new CF().runIO();
    }
}


import java.io.*;
import java.util.*;

public class cf414c {
  static FastIO in = new FastIO(), out = in;

  static long[] count;
  static long[] max;
  public static void main(String[] args) {
    int n = in.nextInt();
    int[] v = new int[1<<n];
    for(int i=0; i<1<<n; i++) v[i] = in.nextInt();
    count = new long[n+1];
    max = new long[n+1];
    go(v, 0, 1<<n, n);

    int m = in.nextInt();
    for(int z=0; z<m; z++) {
      long ret = 0;
      int x = in.nextInt();
      for(int i=0; i<=x; i++)
        count[i] = max[i] - count[i];
      for(int i=0; i<=n; i++)
        ret += count[i];
      out.println(ret);
    }

    out.close();
  }
  static void go(int[] v, int l, int r, int level) {
    if(l+1 == r) return;
    int mid = (l+r)/2;
    go(v, l, mid, level-1);
    go(v, mid, r, level-1);

    int size = 1<<(level-1);
    max[level] += size*1L*size;

    int[] tmp = new int[2*size];
    int cur = 0;
    int ind1 = l, ind2 = mid;
    while(ind1 < mid && ind2 < r) {
      if(v[ind1] <= v[ind2]) {
        tmp[cur++] = v[ind1++];
      }
      else {
        count[level] += mid-ind1;
        tmp[cur++] = v[ind2++];
      }
    }
    while(ind1 < mid) {
      tmp[cur++] = v[ind1++];
    }
    while(ind2 < r) {
      tmp[cur++] = v[ind2++];
    }
    for(int i=0; i<tmp.length; i++)
      v[l+i] = tmp[i];
  }

  static class FastIO extends PrintWriter {
    BufferedReader br;
    StringTokenizer st;

    public FastIO() {
      this(System.in, System.out);
    }

    public FastIO(InputStream in, OutputStream out) {
      super(new BufferedWriter(new OutputStreamWriter(out)));
      br = new BufferedReader(new InputStreamReader(in));
      scanLine();
    }

    public void scanLine() {
      try {
        st = new StringTokenizer(br.readLine().trim());
      } catch (Exception e) {
        throw new RuntimeException(e.getMessage());
      }
    }

    public int numTokens() {
      if (!st.hasMoreTokens()) {
        scanLine();
        return numTokens();
      }
      return st.countTokens();
    }

    public String next() {
      if (!st.hasMoreTokens()) {
        scanLine();
        return next();
      }
      return st.nextToken();
    }

    public double nextDouble() {
      return Double.parseDouble(next());
    }

    public long nextLong() {
      return Long.parseLong(next());
    }

    public int nextInt() {
      return Integer.parseInt(next());
    }
  }
}


import java.io.*;
import java.util.*;

public class cf414c {
  static FastIO in = new FastIO(), out = in;

  static long[] count1, count2;
  public static void main(String[] args) {
    int n = in.nextInt();
    int[] v = new int[1<<n];
    for(int i=0; i<1<<n; i++) v[i] = in.nextInt();
    count1 = new long[n+1];
    count2 = new long[n+1];
    go(v, 0, 1<<n, n);

    int m = in.nextInt();
    for(int z=0; z<m; z++) {
      long ret = 0;
      int x = in.nextInt();
      for(int i=0; i<=x; i++) {
        long tmp = count1[i];
        count1[i] = count2[i];
        count2[i] = tmp;
      }
      for(int i=0; i<=n; i++)
        ret += count1[i];
      out.println(ret);
    }
    out.close();
  }
  static void go(int[] v, int l, int r, int level) {
    if(l+1 == r) return;
    int mid = (l+r)/2;
    go(v, l, mid, level-1);
    go(v, mid, r, level-1);

    int[] tmp = new int[r-l];
    int cur = 0;
    int ind1 = l, ind2 = mid;
    while(ind1 < mid && ind2 < r) {
      if(v[ind1] < v[ind2]) {
        count2[level] += r-ind2;
        tmp[cur++] = v[ind1++];
      }
      else if(v[ind1] > v[ind2]) {
        count1[level] += mid-ind1;
        tmp[cur++] = v[ind2++];
      }
      else {
        int c1 = 0;
        int c2 = 0;
        int val = v[ind1];
        while(ind1 < mid && v[ind1] == val) {
          ind1++;
          c1++;
        }
        while(ind2 < r && v[ind2] == val) {
          ind2++;
          c2++;
        }
        for(int i=0; i<c1+c2; i++)
          tmp[cur++] = val;
        count1[level] += (mid-ind1)*1L*c2;
        count2[level] += (r-ind2)*1L*c1;
      }
    }
    while(ind1 < mid) {
      tmp[cur++] = v[ind1++];
    }
    while(ind2 < r) {
      tmp[cur++] = v[ind2++];
    }
    for(int i=0; i<tmp.length; i++)
      v[l+i] = tmp[i];
  }

  static class FastIO extends PrintWriter {
    BufferedReader br;
    StringTokenizer st;

    public FastIO() {
      this(System.in, System.out);
    }

    public FastIO(InputStream in, OutputStream out) {
      super(new BufferedWriter(new OutputStreamWriter(out)));
      br = new BufferedReader(new InputStreamReader(in));
      scanLine();
    }

    public void scanLine() {
      try {
        st = new StringTokenizer(br.readLine().trim());
      } catch (Exception e) {
        throw new RuntimeException(e.getMessage());
      }
    }

    public int numTokens() {
      if (!st.hasMoreTokens()) {
        scanLine();
        return numTokens();
      }
      return st.countTokens();
    }

    public String next() {
      if (!st.hasMoreTokens()) {
        scanLine();
        return next();
      }
      return st.nextToken();
    }

    public double nextDouble() {
      return Double.parseDouble(next());
    }

    public long nextLong() {
      return Long.parseLong(next());
    }

    public int nextInt() {
      return Integer.parseInt(next());
    }
  }
}


import java.io.InputStreamReader;
import java.io.IOException;
import java.util.InputMismatchException;
import java.io.PrintStream;
import java.io.BufferedReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.Reader;
import java.io.Writer;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 * @author Nipuna Samarasekara
 */
public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		FastScanner in = new FastScanner(inputStream);
		FastPrinter out = new FastPrinter(outputStream);
		TaskC solver = new TaskC();
		solver.solve(1, in, out);
		out.close();
	}
}

class TaskC {
    /////////////////////////////////////////////////////////////

    long[] level;
    long[] sum;
    static int[] A;
    int N;

    public void solve(int testNumber, FastScanner in, FastPrinter out) {
    level=new long[30];
    sum= new long[30];

   int n=in.nextInt();
   A=in.readIntArray((int)Math.pow(2,n));
    N=(int)Math.pow(2,n);

        for (int i = 1; i < 30; i++) {
            sum[i]= (long)(Math.pow(2,i)-1)*(long)(N/2);
        }
        for (int i = 29; i >0 ; i--) {
            sum[i]-=sum[i-1];
        }
     sort(0,N);

     int q=in.nextInt();
        for (int i = 0; i < q; i++) {
            int t=in.nextInt();

            for (int j = 1; j <= t ; j++) {
              level[j]=sum[j]-level[j];

            }
            long ans=0;
            for (int k = 1; k < 30; k++) {
                ans+=level[k];
            }
            out.println(ans);

        }

    }
    void sort(int low,int high){
        if(high-low==1)return;
        int len=(high-low)/2;
        sort(low,low+len);
        sort(low+len,high);
     //   System.out.println(low+" "+high+" ");
       int cc=high-low;
        int pos=0;
        while(cc>1){
            cc/=2;pos++;
        }
      int[] temp= new int[len*2];
       int ll=low,rr=low+len;
        while(ll<len+low&&rr<high){

            if(A[ll]<A[rr]){ll++;
            continue;
            }
            if(A[ll]>A[rr]){rr++;
                continue;
            }
            if(A[ll]==A[rr]){
                int val=A[ll];
                long c1=0,c2=0;
                while(ll<len+low&&A[ll]==val){ll++;c1++;}
                while(rr<high&&A[rr]==val){rr++;c2++;}
             //   System.out.println(A[ll]+" "+A[rr]+" "+c1+" "+c2);
             sum[pos]-=c1*c2;
            }

        }

        ll=low;rr=low+len;
        for (int i = 0; i < 2 * len; i++) {
            if(rr==high){
                temp[i]=A[ll];
                ll++;
                continue;
            }
            if(ll==low+len){
                temp[i]=A[rr];
                rr++;
                continue;
            }
            if(A[ll]<=A[rr]){
                temp[i]=A[ll];
                ll++;
            }
            else{
                temp[i]=A[rr];
                rr++;
                level[pos]+=low+len-ll;
            }
        }
        for (int i = 0; i < 2*len; i++) {
         A[low+i]=temp[i];
        }
    }
}

class FastScanner extends BufferedReader {

    public FastScanner(InputStream is) {
        super(new InputStreamReader(is));
    }

    public int read() {
        try {
            int ret = super.read();
//            if (isEOF && ret < 0) {
//                throw new InputMismatchException();
//            }
//            isEOF = ret == -1;
            return ret;
        } catch (IOException e) {
            throw new InputMismatchException();
        }
    }

    static boolean isWhiteSpace(int c) {
        return c >= 0 && c <= 32;
    }

    public int nextInt() {
        int c = read();
        while (isWhiteSpace(c)) {
            c = read();
        }
        int sgn = 1;
        if (c == '-') {
            sgn = -1;
            c = read();
        }
        int ret = 0;
        while (c >= 0 && !isWhiteSpace(c)) {
            if (c < '0' || c > '9') {
                throw new NumberFormatException("digit expected " + (char) c
                        + " found");
            }
            ret = ret * 10 + c - '0';
            c = read();
        }
        return ret * sgn;
    }

    public String readLine() {
        try {
            return super.readLine();
        } catch (IOException e) {
            return null;
        }
    }

    public int[] readIntArray(int n) {
        int[] ret = new int[n];
        for (int i = 0; i < n; i++) {
            ret[i] = nextInt();
        }
        return ret;
    }

}

class FastPrinter extends PrintWriter {

    public FastPrinter(OutputStream out) {
        super(out);
    }

    public FastPrinter(Writer out) {
        super(out);
    }

}


import java.io.InputStreamReader;
import java.io.IOException;
import java.util.InputMismatchException;
import java.io.PrintStream;
import java.io.BufferedReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.Reader;
import java.io.Writer;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 * @author Nipuna Samarasekara
 */
public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		FastScanner in = new FastScanner(inputStream);
		FastPrinter out = new FastPrinter(outputStream);
		TaskC solver = new TaskC();
		solver.solve(1, in, out);
		out.close();
	}
}

class TaskC {
    /////////////////////////////////////////////////////////////

    long[] level;
    long[] sum;
    static int[] A;
    int N;

    public void solve(int testNumber, FastScanner in, FastPrinter out) {
    level=new long[30];
    sum= new long[30];
   int n=in.nextInt();
   A=in.readIntArray((int)Math.pow(2,n));
    N=(int)Math.pow(2,n);
     sort(0,N);
   long tot=0;
        for (int i = 1; i < 30; i++) {
           sum[i]= (long)(Math.pow(2,i)-1)*(long)(N/2);
        }
        for (int i = 29; i >0 ; i--) {
          sum[i]-=sum[i-1];
        }
     int q=in.nextInt();
        for (int i = 0; i < q; i++) {
            int t=in.nextInt();

            for (int j = 1; j <= t ; j++) {
              level[j]=sum[j]-level[j];

            }
            long ans=0;
            for (int k = 1; k < 30; k++) {
                ans+=level[k];
            }
            out.println(ans);
           // deb(level);

        }

    }
    void sort(int low,int high){
        if(high-low==1)return;
        int len=(high-low)/2;
        sort(low,low+len);
        sort(low+len,high);
     //   System.out.println(low+" "+high+" ");
       int cc=high-low;
        int pos=0;
        while(cc>1){
            cc/=2;pos++;
        }
      int[] temp= new int[len*2];
       int ll=low,rr=low+len;
        for (int i = 0; i < 2 * len; i++) {
            if(rr==high){
                temp[i]=A[ll];
                ll++;
                continue;
            }
            if(ll==low+len){
                temp[i]=A[rr];
                rr++;
                continue;
            }
            if(A[ll]<=A[rr]){
                temp[i]=A[ll];
                ll++;
            }
            else{
                temp[i]=A[rr];
                rr++;
                level[pos]+=low+len-ll;
            }
        }
        for (int i = 0; i < 2*len; i++) {
         A[low+i]=temp[i];
        }
    }
}

class FastScanner extends BufferedReader {

    public FastScanner(InputStream is) {
        super(new InputStreamReader(is));
    }

    public int read() {
        try {
            int ret = super.read();
//            if (isEOF && ret < 0) {
//                throw new InputMismatchException();
//            }
//            isEOF = ret == -1;
            return ret;
        } catch (IOException e) {
            throw new InputMismatchException();
        }
    }

    static boolean isWhiteSpace(int c) {
        return c >= 0 && c <= 32;
    }

    public int nextInt() {
        int c = read();
        while (isWhiteSpace(c)) {
            c = read();
        }
        int sgn = 1;
        if (c == '-') {
            sgn = -1;
            c = read();
        }
        int ret = 0;
        while (c >= 0 && !isWhiteSpace(c)) {
            if (c < '0' || c > '9') {
                throw new NumberFormatException("digit expected " + (char) c
                        + " found");
            }
            ret = ret * 10 + c - '0';
            c = read();
        }
        return ret * sgn;
    }

    public String readLine() {
        try {
            return super.readLine();
        } catch (IOException e) {
            return null;
        }
    }

    public int[] readIntArray(int n) {
        int[] ret = new int[n];
        for (int i = 0; i < n; i++) {
            ret[i] = nextInt();
        }
        return ret;
    }

}

class FastPrinter extends PrintWriter {

    public FastPrinter(OutputStream out) {
        super(out);
    }

    public FastPrinter(Writer out) {
        super(out);
    }

}


import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class C {
	static long[] inversions;
	static long[] oddversions;
	public static void main(String[] args) throws Exception{
		int n = readInt();
		inversions = new long[n+1];
		oddversions = new long[n+1];
		int nn = 1;
		StringBuilder sb = new StringBuilder();
		for(int i = 1; i <= n; i++){
			nn*=2;
		}
		int[] list = new int[nn];
		for(int i = 0 ; i < nn; i++){
			list[i] = readInt();
		}
		merge(list, 0, nn-1, n);
		boolean[] rev = new boolean[n+1];
		int m = readInt();
		for(int i = 0; i < m; i++){
			int q = readInt();
			for(int j = 1; j <= q; j++){
				rev[j] = !rev[j];
			}
			long ans = 0;
			for(int j = 1; j <= n; j++){
				if(rev[j]){
					ans += oddversions[j];
				}
				else{
					ans += inversions[j];
				}
			}
			sb.append(ans);
			sb.append("\n");
		}
		System.out.println(sb);
	}
	static int[] merge(int[] list, int a, int b, int lvl){
		if(a == b){
			int[] c = new int[1];
			c[0] = list[a];
			if(c[0] > 1){
			}
			return c;
		}

		int[] l = merge(list, a, ((a+b)/2), lvl-1);
		int[] r = merge(list, ((a+b)/2) + 1 , b, lvl-1);
		int len = l.length;
		int[] c = new int[2*len];
		int i = 0;
		int j = 0;
		while(i+j < 2*len){
			if(i == l.length){
				c[i+j] = r[j];
				j++;
			}
			else if(j == r.length){
				c[i+j] = l[i];
				i++;
			}
			else{
				if(l[i] <= r[j]){
					c[i+j] = l[i];
					i++;
				}
				else{
					c[i + j] = r[j];
					inversions[lvl]+= len-i;
					j++;
				}
			}
		}
		i = len-1;
		j = len-1;
		while(i+j > - 2){
			if(j == -1){
				i--;
			}
			else if(i == -1){
				j--;
			}
			else{
				if(l[i] < r[j]){
					oddversions[lvl]+= i+1;
					j--;
				}
				else{
					i--;
				}
			}
		}

		return c;

	}
	static BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
	static StringTokenizer st = new StringTokenizer(" ");
	static String readString() throws Exception{
		while(!st.hasMoreTokens()){
			st = new StringTokenizer(stdin.readLine());
		}
		return st.nextToken();
	}
	static int readInt() throws Exception {
		return Integer.parseInt(readString());
	}
	static long readLong() throws Exception {
		return Long.parseLong(readString());
	}
}


import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class C {
	static long[] inversions;
	static long[] oddversions;
	public static void main(String[] args) throws Exception{
		int n = readInt();
		inversions = new long[n+1];
		oddversions = new long[n+1];
		int nn = 1;
		StringBuilder sb = new StringBuilder();
		for(int i = 1; i <= n; i++){
			nn*=2;
		}
		int[] list = new int[nn];
		for(int i = 0 ; i < nn; i++){
			list[i] = readInt();
		}
		merge(list, 0, nn-1, n);
		boolean[] rev = new boolean[n+1];
		int m = readInt();
		for(int i = 0; i < m; i++){
			int q = readInt();
			for(int j = 1; j <= q; j++){
				rev[j] = !rev[j];
			}
			long ans = 0;
			for(int j = 1; j <= n; j++){
				if(rev[j]){
					ans += oddversions[j];
				}
				else{
					ans += inversions[j];
				}
			}
			sb.append(ans);
			sb.append("\n");
		}
		System.out.println(sb);
	}
	static int[] merge(int[] list, int a, int b, int lvl){
		if(a == b){
			int[] c = new int[1];
			c[0] = list[a];
			return c;
		}

		int[] l = merge(list, a, ((a+b)/2), lvl-1);
		int[] r = merge(list, ((a+b)/2) + 1 , b, lvl-1);
		int len = l.length;
		int[] c = new int[2*len];
		int i = 0;
		int j = 0;
		while(i+j < 2*len){
			if(i == l.length){
				c[i+j] = r[j];
				j++;
			}
			else if(j == r.length){
				c[i+j] = l[i];
				i++;
			}
			else{
				if(l[i] < r[j]){
					c[i+j] = l[i];
					oddversions[lvl]+= len-j;
					i++;
				}
				else if(l[i] == r[j]){
					c[i+j] = l[i];
					i++;
					c[i+j] = r[j];
					j++;
				}
				else{
					c[i + j] = r[j];
					inversions[lvl]+= len-i;
					i++;
				}
			}
		}

		return c;

	}
	static BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
	static StringTokenizer st = new StringTokenizer(" ");
	static String readString() throws Exception{
		while(!st.hasMoreTokens()){
			st = new StringTokenizer(stdin.readLine());
		}
		return st.nextToken();
	}
	static int readInt() throws Exception {
		return Integer.parseInt(readString());
	}
	static long readLong() throws Exception {
		return Long.parseLong(readString());
	}
}


import java.util.*;
import java.io.*;
public class C {
    public static long time = 0;
    public static void main(String[] args) throws Exception {
        time = System.currentTimeMillis();

        IN = System.in;
        OUT = System.out;
        in = new BufferedReader(new InputStreamReader(IN));
        out = new PrintWriter(OUT, FLUSH);
        solveOne();
        out.flush();
    }
    public static void solveOne() throws Exception {
        int n1 = ni();
        int[] l1 = nil(1 << n1);
        long[] count = new long[n1 + 1];
        long[] opp = new long[n1 + 1];
        for (int i = 1; i <= n1; i++){
            int segNo = 1 << (n1 - i);
            int halfLen = 1 << (i - 1);
//          px(i ,segNo,halfLen);
            for (int j = 0; j < segNo; j++){
                int start1 = j * (1 << i);
                int end1 = start1 + (1 << (i - 1) );
                int end2 = start1 + (1 << i) - 1;
                Arrays.sort(l1, start1, end1);
                Arrays.sort(l1, end1, start1 + (1 << i));
                {
                    int ptr = 0;
                    for (int k = 0; k < halfLen; k++){
                        for (;;){
                            if (ptr >= halfLen) break;
                            if (l1[start1 + k] > l1[end1 + ptr]){
                                ptr++;
                            }
                            else {
                                break;
                            }
                        }
                        count[i] += (long)ptr;
                    }
                }
                {
                    int ptr = 0;
                    for (int k = 0; k < halfLen; k++){
                        for (;;){
                            if (ptr >= halfLen) break;
                            if (l1[start1 + k] >= l1[end1 + ptr]){
                                ptr++;
                            }
                            else {
                                break;
                            }
                        }
                        opp[i] += (long)(halfLen - ptr);
                    }
                }
            }
//          px(l1);
        }
//      px(count);
//      px(opp);
//      px(total);
        int m1 = ni();
        for (int qq = 0; qq < m1; qq++){
            int k1 = ni();
            for (int i = 0; i <= k1; i++){
                long temp = count[i];
                count[i] = opp[i];
                opp[i] = temp;
            }
//          px(count);
//          px(opp);
            long sum = 0;
            for (long e: count){
                sum += e;
            }
            pn(sum);
        }
    }

    public static void solveTwo() throws Exception {

    }

    public static void solveThree() throws Exception {

    }

    public static BufferedReader in;
    public static StringTokenizer st;
    public static InputStream IN;
    public static OutputStream OUT;
    public static String nx() throws Exception {
        for (;st == null || !st.hasMoreTokens();){
            String k1 = in.readLine();
            if (k1 == null) return null;
            st = new StringTokenizer(k1);
        }
        return st.nextToken();
    }
    public static int ni () throws Exception {
        return Integer.parseInt(nx());
    }
    public static long nl() throws Exception{
        return Long.parseLong(nx());
    }
    public static double nd() throws Exception{
        return Double.parseDouble(nx());
    }
    private static int[] nil(int n1) throws Exception {
        int[] l1 = new int[n1];
        for (int i = 0 ;i < n1; i++){
            l1[i] = ni();
        }
        return l1;
    }
    public static void px(Object ... l1){
        System.out.println(Arrays.deepToString(l1));
    }
    public static boolean FLUSH = false;
    public static PrintWriter out;
    public static void p(Object ... l1){
        for (int i = 0; i < l1.length; i++){
            if (i != 0) out.print(' ');
            out.print(l1[i].toString());
        }
    }
    public static void pn(Object ... l1){
        for (int i = 0; i < l1.length; i++){
            if (i != 0) out.print(' ');
            out.print(l1[i].toString());
        }
        out.println();
    }

    public static void pn(Collection l1){
        boolean first = true;
        for (Object e: l1){
            if (first) first = false;
            else out.print(' ');
            out.print(e.toString());
        }
        out.println();
    }

}


import java.util.*;
import java.io.*;
public class C {
    public static long time = 0;
    public static void main(String[] args) throws Exception {
        time = System.currentTimeMillis();

        IN = System.in;
        OUT = System.out;
        in = new BufferedReader(new InputStreamReader(IN));
        out = new PrintWriter(OUT, FLUSH);
        solveOne();
        out.flush();
    }
    public static long total(long n1){
        return n1 * (n1 - 1l) / 2l;
    }
    public static void solveOne() throws Exception {
        int n1 = ni();
        int[] l1 = nil(1 << n1);
        long[] count = new long[n1 + 1];
        long[] opp = new long[n1 + 1];
        for (int i = 1; i <= n1; i++){
            int segNo = 1 << (n1 - i);
            int halfLen = 1 << (i - 1);
//          px(i ,segNo,halfLen);
            for (int j = 0; j < segNo; j++){
                int start1 = j * (1 << i);
                int end1 = start1 + (1 << (i - 1) );
                int end2 = start1 + (1 << i) - 1;
                Arrays.sort(l1, start1, end1);
                Arrays.sort(l1, end1, start1 + (1 << i));
                {
                    int ptr = 0;
                    for (int k = 0; k < halfLen; k++){
                        for (;;){
                            if (ptr >= halfLen) break;
                            if (l1[start1 + k] > l1[end1 + ptr]){
                                ptr++;
                            }
                            else {
                                break;
                            }
                        }
                        count[i] += (long)ptr;
                    }
                }
                {
                    int ptr = 0;
                    for (int k = 0; k < halfLen; k++){
                        for (;;){
                            if (ptr >= halfLen) break;
                            if (l1[start1 + k] < l1[end2 - ptr]){
                                ptr++;
                            }
                            else {
                                break;
                            }
                        }
                        opp[i] += (long)ptr;
                    }
                }
            }
        }
//      px(count);
//      px(opp);
        long[] total = new long[n1 + 1];
        for (int i = 0 ; i < total.length; i++){
            total[i] += (1l << (i - 1)) * (1l << (i - 1)) * (1l << (n1 - i));
        }
//      px(total);
        int m1 = ni();
        for (int qq = 0; qq < m1; qq++){
            int k1 = ni();
            for (int i = 0; i <= k1; i++){
                long temp = count[i];
                count[i] = opp[i];
                opp[i] = temp;
            }
            long sum = 0;
            for (long e: count){
                sum += e;
            }
            pn(sum);
        }
    }

    public static void solveTwo() throws Exception {

    }

    public static void solveThree() throws Exception {

    }

    public static BufferedReader in;
    public static StringTokenizer st;
    public static InputStream IN;
    public static OutputStream OUT;
    public static String nx() throws Exception {
        for (;st == null || !st.hasMoreTokens();){
            String k1 = in.readLine();
            if (k1 == null) return null;
            st = new StringTokenizer(k1);
        }
        return st.nextToken();
    }
    public static int ni () throws Exception {
        return Integer.parseInt(nx());
    }
    public static long nl() throws Exception{
        return Long.parseLong(nx());
    }
    public static double nd() throws Exception{
        return Double.parseDouble(nx());
    }
    private static int[] nil(int n1) throws Exception {
        int[] l1 = new int[n1];
        for (int i = 0 ;i < n1; i++){
            l1[i] = ni();
        }
        return l1;
    }
    public static void px(Object ... l1){
        System.out.println(Arrays.deepToString(l1));
    }
    public static boolean FLUSH = false;
    public static PrintWriter out;
    public static void p(Object ... l1){
        for (int i = 0; i < l1.length; i++){
            if (i != 0) out.print(' ');
            out.print(l1[i].toString());
        }
    }
    public static void pn(Object ... l1){
        for (int i = 0; i < l1.length; i++){
            if (i != 0) out.print(' ');
            out.print(l1[i].toString());
        }
        out.println();
    }

    public static void pn(Collection l1){
        boolean first = true;
        for (Object e: l1){
            if (first) first = false;
            else out.print(' ');
            out.print(e.toString());
        }
        out.println();
    }

}


import java.util.*;
import java.io.*;
public class C {
    public static long time = 0;
    public static void main(String[] args) throws Exception {
        time = System.currentTimeMillis();

        IN = System.in;
        OUT = System.out;
        in = new BufferedReader(new InputStreamReader(IN));
        out = new PrintWriter(OUT, FLUSH);
        solveOne();
        out.flush();
    }
    public static void solveOne() throws Exception {
        int n1 = ni();
        int[] l1 = nil(1 << n1);
        long[] count = new long[n1 + 1];
        long[] opp = new long[n1 + 1];
        for (int i = 1; i <= n1; i++){
            int segNo = 1 << (n1 - i);
            int halfLen = 1 << (i - 1);
//          px(i ,segNo,halfLen);
            for (int j = 0; j < segNo; j++){
                int start1 = (j << i);
                int end1 = start1 + (1 << (i - 1) );
                int end2 = start1 + (1 << i) - 1;
                Arrays.sort(l1, start1, end1);
                Arrays.sort(l1, end1, start1 + (1 << i));
                {
                    int ptr = 0;
                    for (int k = 0; k < halfLen; k++){
                        for (;;){
                            if (ptr >= halfLen) break;
                            if (l1[start1 + k] > l1[end1 + ptr]){
                                ptr++;
                            }
                            else {
                                break;
                            }
                        }
                        count[i] += (long)ptr;
                    }
                }
                {
                    int ptr = 0;
                    for (int k = 0; k < halfLen; k++){
                        for (;;){
                            if (ptr >= halfLen) break;
                            if (l1[start1 + k] >= l1[end1 + ptr]){
                                ptr++;
                            }
                            else {
                                break;
                            }
                        }
                        opp[i] += (long)(halfLen - ptr);
                    }
                }
            }
//          px(l1);
        }
//      px(count);
//      px(opp);
//      px(total);
        int m1 = ni();
        for (int qq = 0; qq < m1; qq++){
            int k1 = ni();
            for (int i = 0; i <= k1; i++){
                long temp = count[i];
                count[i] = opp[i];
                opp[i] = temp;
            }
//          px(count);
//          px(opp);
            long sum = 0;
            for (long e: count){
                sum += e;
            }
            pn(sum);
        }
    }

    public static void solveTwo() throws Exception {

    }

    public static void solveThree() throws Exception {

    }

    public static BufferedReader in;
    public static StringTokenizer st;
    public static InputStream IN;
    public static OutputStream OUT;
    public static String nx() throws Exception {
        for (;st == null || !st.hasMoreTokens();){
            String k1 = in.readLine();
            if (k1 == null) return null;
            st = new StringTokenizer(k1);
        }
        return st.nextToken();
    }
    public static int ni () throws Exception {
        return Integer.parseInt(nx());
    }
    public static long nl() throws Exception{
        return Long.parseLong(nx());
    }
    public static double nd() throws Exception{
        return Double.parseDouble(nx());
    }
    private static int[] nil(int n1) throws Exception {
        int[] l1 = new int[n1];
        for (int i = 0 ;i < n1; i++){
            l1[i] = ni();
        }
        return l1;
    }
    public static void px(Object ... l1){
        System.out.println(Arrays.deepToString(l1));
    }
    public static boolean FLUSH = false;
    public static PrintWriter out;
    public static void p(Object ... l1){
        for (int i = 0; i < l1.length; i++){
            if (i != 0) out.print(' ');
            out.print(l1[i].toString());
        }
    }
    public static void pn(Object ... l1){
        for (int i = 0; i < l1.length; i++){
            if (i != 0) out.print(' ');
            out.print(l1[i].toString());
        }
        out.println();
    }

    public static void pn(Collection l1){
        boolean first = true;
        for (Object e: l1){
            if (first) first = false;
            else out.print(' ');
            out.print(e.toString());
        }
        out.println();
    }

}


import java.util.*;
import java.io.*;
public class C {
    public static long time = 0;
    public static void main(String[] args) throws Exception {
        time = System.currentTimeMillis();

        IN = System.in;
        OUT = System.out;
        in = new BufferedReader(new InputStreamReader(IN));
        out = new PrintWriter(OUT, FLUSH);
        solveOne();
        out.flush();
    }
    public static void solveOne() throws Exception {
        int n1 = ni();
        int[] l1 = nil(1 << n1);
        long[] count = new long[n1 + 1];
        long[] opp = new long[n1 + 1];
        for (int i = 1; i <= n1; i++){
            int segNo = 1 << (n1 - i);
            int halfLen = 1 << (i - 1);
//          px(i ,segNo,halfLen);
            for (int j = 0; j < segNo; j++){
                int start1 = (j << i);
                int end1 = start1 + (1 << (i - 1) );
                int end2 = start1 + (1 << i) - 1;
                Arrays.sort(l1, start1, end1);
                Arrays.sort(l1, end1, start1 + (1 << i));
                {
                    int ptr = 0;
                    for (int k = 0; k < halfLen; k++){
                        for (;;){
                            if (ptr >= halfLen) break;
                            if (l1[start1 + k] > l1[end1 + ptr]){
                                ptr++;
                            }
                            else {
                                break;
                            }
                        }
                        count[i] += (long)ptr;
                    }
                }
                {
                    int ptr = 0;
                    for (int k = 0; k < halfLen; k++){
                        for (;;){
                            if (ptr >= halfLen) break;
                            if (l1[start1 + k] >= l1[end1 + ptr]){
                                ptr++;
                            }
                            else {
                                break;
                            }
                        }
                        opp[i] += (long)(halfLen - ptr);
                    }
                }
            }
//          px(l1);
        }
//      px(count);
//      px(opp);
//      px(total);
        int m1 = ni();
        for (int qq = 0; qq < m1; qq++){
            int k1 = ni();
            long sum = 0;
            for (int i = 0; i <= k1; i++){
                long temp = count[i];
                count[i] = opp[i];
                opp[i] = temp;
                sum += count[i];
            }
//          px(count);
//          px(opp);
            pn(sum);
        }
    }

    public static void solveTwo() throws Exception {

    }

    public static void solveThree() throws Exception {

    }

    public static BufferedReader in;
    public static StringTokenizer st;
    public static InputStream IN;
    public static OutputStream OUT;
    public static String nx() throws Exception {
        for (;st == null || !st.hasMoreTokens();){
            String k1 = in.readLine();
            if (k1 == null) return null;
            st = new StringTokenizer(k1);
        }
        return st.nextToken();
    }
    public static int ni () throws Exception {
        return Integer.parseInt(nx());
    }
    public static long nl() throws Exception{
        return Long.parseLong(nx());
    }
    public static double nd() throws Exception{
        return Double.parseDouble(nx());
    }
    private static int[] nil(int n1) throws Exception {
        int[] l1 = new int[n1];
        for (int i = 0 ;i < n1; i++){
            l1[i] = ni();
        }
        return l1;
    }
    public static void px(Object ... l1){
        System.out.println(Arrays.deepToString(l1));
    }
    public static boolean FLUSH = false;
    public static PrintWriter out;
    public static void p(Object ... l1){
        for (int i = 0; i < l1.length; i++){
            if (i != 0) out.print(' ');
            out.print(l1[i].toString());
        }
    }
    public static void pn(Object ... l1){
        for (int i = 0; i < l1.length; i++){
            if (i != 0) out.print(' ');
            out.print(l1[i].toString());
        }
        out.println();
    }

    public static void pn(Collection l1){
        boolean first = true;
        for (Object e: l1){
            if (first) first = false;
            else out.print(' ');
            out.print(e.toString());
        }
        out.println();
    }

}


import java.util.*;
import java.io.*;
public class C {
    public static long time = 0;
    public static void main(String[] args) throws Exception {
        time = System.currentTimeMillis();

        IN = System.in;
        OUT = System.out;
        in = new BufferedReader(new InputStreamReader(IN));
        out = new PrintWriter(OUT, FLUSH);
        solveOne();
        out.flush();
    }
    public static long total(long n1){
        return n1 * (n1 - 1l) / 2l;
    }
    public static void solveOne() throws Exception {
        long[] totalList = new long[20];
        for (int i = 0; i < 20; i++){

        }
        int n1 = ni();
        int[] l1 = nil(1 << n1);
        long[] count = new long[n1 + 1];
        long[] opp = new long[n1 + 1];
        for (int i = 1; i <= n1; i++){
            int segNo = 1 << (n1 - i);
            int halfLen = 1 << (i - 1);
//          px(i ,segNo,halfLen);
            for (int j = 0; j < segNo; j++){
                int start1 = j * (1 << i);
                int end1 = start1 + (1 << (i - 1) );
                int end2 = start1 + (1 << i) - 1;
                Arrays.sort(l1, start1, end1);
                Arrays.sort(l1, end1, start1 + (1 << i));
                {
                    int ptr = 0;
                    for (int k = 0; k < halfLen; k++){
                        for (;;){
                            if (ptr >= halfLen) break;
                            if (l1[start1 + k] > l1[end1 + ptr]){
                                ptr++;
                            }
                            else {
                                break;
                            }
                        }
                        count[i] += ptr;
                    }
                }
                {
                    int ptr = 0;
                    for (int k = 0; k < halfLen; k++){
                        for (;;){
                            if (ptr >= halfLen) break;
                            if (l1[start1 + k] < l1[end2 - ptr]){
                                ptr++;
                            }
                            else {
                                break;
                            }
                        }
                        opp[i] += ptr;
                    }
                }
            }
        }
//      px(count);
        long[] total = new long[n1 + 1];
        for (int i = 0 ; i < total.length; i++){
            total[i] += (1 << (i - 1)) * (1 << (i - 1)) * (1 << (n1 - i));
        }
//      px(total);
        int m1 = ni();
        for (int qq = 0; qq < m1; qq++){
            int k1 = ni();
            for (int i = 0; i <= k1; i++){
                long temp = count[i];
                count[i] = opp[i];
                opp[i] = temp;
            }
            long sum = 0;
            for (long e: count){
                sum += e;
            }
            pn(sum);
        }
    }

    public static void solveTwo() throws Exception {

    }

    public static void solveThree() throws Exception {

    }

    public static BufferedReader in;
    public static StringTokenizer st;
    public static InputStream IN;
    public static OutputStream OUT;
    public static String nx() throws Exception {
        for (;st == null || !st.hasMoreTokens();){
            String k1 = in.readLine();
            if (k1 == null) return null;
            st = new StringTokenizer(k1);
        }
        return st.nextToken();
    }
    public static int ni () throws Exception {
        return Integer.parseInt(nx());
    }
    public static long nl() throws Exception{
        return Long.parseLong(nx());
    }
    public static double nd() throws Exception{
        return Double.parseDouble(nx());
    }
    private static int[] nil(int n1) throws Exception {
        int[] l1 = new int[n1];
        for (int i = 0 ;i < n1; i++){
            l1[i] = ni();
        }
        return l1;
    }
    public static void px(Object ... l1){
        System.out.println(Arrays.deepToString(l1));
    }
    public static boolean FLUSH = false;
    public static PrintWriter out;
    public static void p(Object ... l1){
        for (int i = 0; i < l1.length; i++){
            if (i != 0) out.print(' ');
            out.print(l1[i].toString());
        }
    }
    public static void pn(Object ... l1){
        for (int i = 0; i < l1.length; i++){
            if (i != 0) out.print(' ');
            out.print(l1[i].toString());
        }
        out.println();
    }

    public static void pn(Collection l1){
        boolean first = true;
        for (Object e: l1){
            if (first) first = false;
            else out.print(' ');
            out.print(e.toString());
        }
        out.println();
    }

}


import java.io.BufferedReader;
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskC solver = new TaskC();
		solver.solve(1, in, out);
		out.close();
	}
}

class TaskC {

	public void solve(int testNumber, InputReader in, PrintWriter out) {
		int n = in.nextInt();
		int len = 1 << n;
		int[] a = new int[len];
		for (int i = 0; i < len; i++) {
			a[i] = in.nextInt();
		}

		long[] inv = new long[n + 1];
		long[] total = new long[n + 1];
		for (int i = 0; i <= n; i++) {
			int block = (1 << i);
			int[] b = a.clone();
			for (int j = 0; j < len / block; j++) {
				inv[i] += inversions(b, j * block, (j + 1) * block);
				reverse(b, j * block, (j + 1) * block);
				total[i] += inversions(b, j * block, (j + 1) * block);
			}
		}

		int m = in.nextInt();
		for (int i = 0; i < m; i++) {
			int q = in.nextInt();
			long prev = inv[q];
			long next = total[q] - inv[q];
			for (int j = 0; j < q; j++) {
				inv[j] = total[j] - inv[j];
			}
			inv[q] = next;
			for (int j = q + 1; j <= n; j++) {
				inv[j] += next - prev;
			}
			out.println(inv[n]);
		}
	}

	private void reverse(int[] a, int i, int j) {
		--j;
		for (; i < j; i++, j--) {
			int t = a[i];
			a[i] = a[j];
			a[j] = t;
		}
	}

	static long inversions(int[] a, int low, int high) {
		if (low >= high - 1)
			return 0;
		int mid = (low + high) >>> 1;
		long res1 = inversions(a, low, mid);
		long res2 = inversions(a, mid, high);
		long res = res1 + res2;

		int size = high - low;
		int[] b = new int[size];
		int i = low;
		int j = mid;
		for (int k = 0; k < size; k++) {
			if (j >= high || i < mid && a[i] <= a[j]) {
				b[k] = a[i++];
			} else {
				b[k] = a[j++];
				res += mid - i;
			}
		}
		System.arraycopy(b, 0, a, low, size);
		return res;
	}
}

class InputReader {
	public BufferedReader reader;
	public StringTokenizer tokenizer;

	public InputReader(InputStream stream) {
		reader = new BufferedReader(new InputStreamReader(stream));
	}

	public String next() {
		while (tokenizer == null || !tokenizer.hasMoreTokens()) {
			try {
				tokenizer = new StringTokenizer(reader.readLine());
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		}
		return tokenizer.nextToken();
	}

	public int nextInt() {
		return Integer.parseInt(next());
	}
}


import java.io.BufferedReader;
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskC solver = new TaskC();
		solver.solve(1, in, out);
		out.close();
	}
}

class TaskC {

	public void solve(int testNumber, InputReader in, PrintWriter out) {
		int n = in.nextInt();
		int len = 1 << n;
		int[] a = new int[len];
		for (int i = 0; i < len; i++) {
			a[i] = in.nextInt();
		}

		long[] inv = new long[n + 1];
		for (int i = 0; i <= n; i++) {
			int block = (1 << i);
			int[] b = a.clone();
			for (int j = 0; j < len / block; j++) {
				inv[i] += inversions(b, j * block, (j + 1) * block);
			}
		}

		int m = in.nextInt();
		for (int i = 0; i < m; i++) {
			int q = in.nextInt();
			long block = 1 << q;
			long prev = inv[q];
			long next = len * (block - 1) / 2 - inv[q];
			for (int j = 0; j < q; j++) {
				long b = 1 << j;
				inv[j] = len * (b - 1) / 2 - inv[j];
			}
			inv[q] = next;
			for (int j = q + 1; j <= n; j++) {
				inv[j] += next - prev;
			}
			out.println(inv[n]);
		}
	}

	static long inversions(int[] a, int low, int high) {
		if (low >= high - 1)
			return 0;
		int mid = (low + high) >>> 1;
		long res1 = inversions(a, low, mid);
		long res2 = inversions(a, mid, high);
		long res = res1 + res2;

		int size = high - low;
		int[] b = new int[size];
		int i = low;
		int j = mid;
		for (int k = 0; k < size; k++) {
			if (j >= high || i < mid && a[i] < a[j]) {
				b[k] = a[i++];
			} else {
				b[k] = a[j++];
				res += mid - i;
			}
		}
		System.arraycopy(b, 0, a, low, size);
		return res;
	}
}

class InputReader {
	public BufferedReader reader;
	public StringTokenizer tokenizer;

	public InputReader(InputStream stream) {
		reader = new BufferedReader(new InputStreamReader(stream));
	}

	public String next() {
		while (tokenizer == null || !tokenizer.hasMoreTokens()) {
			try {
				tokenizer = new StringTokenizer(reader.readLine());
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		}
		return tokenizer.nextToken();
	}

	public int nextInt() {
		return Integer.parseInt(next());
	}
}


import java.io.*;
import java.util.*;

public class R240QeMashmokhAndReverseOperations {

	static int n;
	static int a[];
	static long inv[];
	static long equal[];
	static long globalEq;

	public static void main(String args[] ) throws Exception {

		InputReader4 in = new InputReader4(System.in);
	    PrintWriter w = new PrintWriter(System.out);

	    n = in.nextInt();
	    a = new int[(1<<n)];
	    for(int i=0;i<(1<<n);i++)
	    	a[i] = in.nextInt();

	    inv = new long[n+1];
	    equal = new long[n+1];
	    mergeSort(0,(1<<n) - 1);

	    for(int i=1;i<=n;i++)
	    	inv[i] -= equal[i];

	   // System.out.println("Equal " + Arrays.toString(equal));
	   // System.out.println("Inv " + Arrays.toString(inv));

	    int m = in.nextInt();
	    for(int i=0;i<m;i++){
	    	int q = in.nextInt();
	    	for(int j=1;j<=q;j++)
	    		inv[j] = (1L << (n - j))*(1L << (j-1))*(1L << (j-1)) - inv[j] - equal[j];

	    	//System.out.println(Arrays.toString(inv));

	    	long ans = 0;
	    	for(int j=1;j<=n;j++)
	    		ans += inv[j];
	    	w.println(ans);
	    }
	    w.close();
	}

	public static int ip(String s){
		return Integer.parseInt(s);
	}

	public static void mergeSort(int start,int end){
		if(start == end)
			return;
		int mid = (start + end) / 2;
		mergeSort(start,mid);
		mergeSort(mid+1,end);
		int size = Integer.toBinaryString(end - start + 1).length() - 1;
		inv[size] += merge(start,mid,end);
		equal[size] += globalEq;
	}

	public static long merge(int start,int mid,int end){
		int temp[] = new int[end - start + 1];
		long ret = 0;
		int i = start,j = mid + 1,k=0;

		while(i<=mid && j<=end){
			if(a[i] < a[j]){
				ret += j - mid - 1;
				temp[k++] = a[i++];
			}
			else
				temp[k++] = a[j++];
		}

		while(i <= mid){
			temp[k++] = a[i++];
			ret += j - mid - 1;
		}

		while(j <= end)
			temp[k++] = a[j++];

		globalEq = 0;
		i = start;
		j = mid + 1;
		int c1 = 0,c2 = 0,v = -1;
		while(i <= mid && j <= end){
			if(a[i] == v && a[j] == v){
				c1++;
				c2++;
				i++;
				j++;
			}
			else if(a[i] == v){
				c1++;
				i++;
			}
			else if(a[j] == v){
				c2++;
				j++;
			}
			else{
				globalEq += c1*c2;
				c1 = 1;
				c2 = 0;
				v = a[i];
				i++;
			}
		}

		while(i <= mid)
			if(a[i++] == v)
				c1++;

		while(j <= end)
			if(a[j++] == v)
				c2++;

		globalEq += c1*c2;

		for(int x=0;x<k;x++)
			a[start + x] = temp[x];

		return ret;
	}
}

class InputReader4 {

	private InputStream stream;
	private byte[] buf = new byte[1024];
	private int curChar;
	private int numChars;
	private SpaceCharFilter filter;
	public InputReader4(InputStream stream) {
		this.stream = stream;
	}

	public int snext() {
		if (numChars == -1)
			throw new InputMismatchException();
		if (curChar >= numChars) {
			curChar = 0;
			try {
				numChars = stream.read(buf);
			} catch (IOException e) {
				throw new InputMismatchException();
			}
			if (numChars <= 0)
				return -1;
		}
		return buf[curChar++];
	}

	public int nextInt() {
		int c = snext();
		while (isSpaceChar(c))
			c = snext();
		int sgn = 1;
		if (c == '-') {
			sgn = -1;
			c = snext();
		}

		int res = 0;

		do {
			if (c < '0' || c > '9')
				throw new InputMismatchException();
			res *= 10;
			res += c - '0';
			c = snext();
		} while (!isSpaceChar(c));

		return res * sgn;
	}

	public boolean isSpaceChar(int c) {
		if (filter != null)
			return filter.isSpaceChar(c);
		return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
	}

	public interface SpaceCharFilter {
		public boolean isSpaceChar(int ch);
	}
}


import java.io.*;
import java.util.*;

public class R240QeMashmokhAndReverseOperations {

	static int n;
	static int a[];
	static long inv[];
	static long equal[];
	static long globalEq;

	public static void main(String args[] ) throws Exception {

		InputReader4 in = new InputReader4(System.in);
	    PrintWriter w = new PrintWriter(System.out);

	    n = in.nextInt();
	    a = new int[(1<<n)];
	    for(int i=0;i<(1<<n);i++)
	    	a[i] = in.nextInt();

	    inv = new long[n+1];
	    equal = new long[n+1];
	    mergeSort(0,(1<<n) - 1);

	    for(int i=1;i<=n;i++)
	    	inv[i] -= equal[i];

	   // System.out.println("Equal " + Arrays.toString(equal));
	   // System.out.println("Inv " + Arrays.toString(inv));

	    int m = in.nextInt();
	    for(int i=0;i<m;i++){
	    	int q = in.nextInt();
	    	for(int j=1;j<=q;j++)
	    		inv[j] = (1L << (n - j))*(1L << (j-1))*(1L << (j-1)) - inv[j] - equal[j];

	    	//System.out.println(Arrays.toString(inv));

	    	long ans = 0;
	    	for(int j=1;j<=n;j++)
	    		ans += inv[j];
	    	w.println(ans);
	    }
	    w.close();
	}

	public static int ip(String s){
		return Integer.parseInt(s);
	}

	public static void mergeSort(int start,int end){
		if(start == end)
			return;
		int mid = (start + end) / 2;
		mergeSort(start,mid);
		mergeSort(mid+1,end);
		int size = Integer.toBinaryString(end - start + 1).length() - 1;
		inv[size] += merge(start,mid,end);
		equal[size] += globalEq;
	}

	public static long merge(int start,int mid,int end){
		int temp[] = new int[end - start + 1];
		long ret = 0;
		int i = start,j = mid + 1,k=0;

		while(i<=mid && j<=end){
			if(a[i] < a[j]){
				ret += j - mid - 1;
				temp[k++] = a[i++];
			}
			else
				temp[k++] = a[j++];
		}

		while(i <= mid){
			temp[k++] = a[i++];
			ret += j - mid - 1;
		}

		while(j <= end)
			temp[k++] = a[j++];

		globalEq = 0;

		Map<Integer,Integer> left = new TreeMap<Integer,Integer>();
		for(i=start;i<=mid;i++){
			if(left.containsKey(a[i]))
				left.put(a[i], left.get(a[i]) + 1);
			else
				left.put(a[i], 1);
		}
		for(i=mid + 1;i<=end;i++){
			if(left.containsKey(a[i]))
				globalEq += left.get(a[i]);
		}

		for(int x=0;x<k;x++)
			a[start + x] = temp[x];

		return ret;
	}
}

class InputReader4 {

	private InputStream stream;
	private byte[] buf = new byte[1024];
	private int curChar;
	private int numChars;
	private SpaceCharFilter filter;
	public InputReader4(InputStream stream) {
		this.stream = stream;
	}

	public int snext() {
		if (numChars == -1)
			throw new InputMismatchException();
		if (curChar >= numChars) {
			curChar = 0;
			try {
				numChars = stream.read(buf);
			} catch (IOException e) {
				throw new InputMismatchException();
			}
			if (numChars <= 0)
				return -1;
		}
		return buf[curChar++];
	}

	public int nextInt() {
		int c = snext();
		while (isSpaceChar(c))
			c = snext();
		int sgn = 1;
		if (c == '-') {
			sgn = -1;
			c = snext();
		}

		int res = 0;

		do {
			if (c < '0' || c > '9')
				throw new InputMismatchException();
			res *= 10;
			res += c - '0';
			c = snext();
		} while (!isSpaceChar(c));

		return res * sgn;
	}

	public boolean isSpaceChar(int c) {
		if (filter != null)
			return filter.isSpaceChar(c);
		return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
	}

	public interface SpaceCharFilter {
		public boolean isSpaceChar(int ch);
	}
}


import java.io.*;
import java.util.*;

public class R240QeMashmokhAndReverseOperations {

	static int n;
	static int a[];
	static long inv[],other[];
	static long globalEq;

	public static void main(String args[] ) throws Exception {

		InputReader4 in = new InputReader4(System.in);
	    PrintWriter w = new PrintWriter(System.out);

	    n = in.nextInt();
	    a = new int[(1<<n)];
	    for(int i=0;i<(1<<n);i++)
	    	a[i] = in.nextInt();

	    inv = new long[n+1];
	    other = new long[n+1];
	    mergeSort(0,(1<<n) - 1);

	   // System.out.println("Equal " + Arrays.toString(equal));
	   // System.out.println("Inv " + Arrays.toString(inv));

	    int m = in.nextInt();
	    for(int i=0;i<m;i++){
	    	int q = in.nextInt();
	    	for(int j=1;j<=q;j++){
	    		long t = other[j];
	    		other[j] = inv[j];
	    		inv[j] = t;
	    	}
	    	//System.out.println(Arrays.toString(inv));
	    	long ans = 0;
	    	for(int j=1;j<=n;j++)
	    		ans += inv[j];
	    	w.println(ans);
	    }
	    w.close();
	}

	public static int ip(String s){
		return Integer.parseInt(s);
	}

	public static void mergeSort(int start,int end){
		if(start == end)
			return;
		int mid = (start + end) / 2;
		mergeSort(start,mid);
		mergeSort(mid+1,end);
		int size = Integer.toBinaryString(end - start + 1).length() - 1;
		merge(start,mid,end,size);
	}

	public static void merge(int start,int mid,int end,int size){
		int temp[] = new int[end - start + 1];
		int i = start,j = mid + 1,k=0;
		long inve = 0,othr = 0;

		while(i <= mid && j <= end){
			if(a[i] <= a[j])
				temp[k++] = a[i++];
			else{
				inve += mid + 1 - i;
				temp[k++] = a[j++];
			}
		}

		while(i <= mid)
			temp[k++] = a[i++];

		while(j <= end)
			temp[k++] = a[j++];

		for(i=start,j=mid+1;i<=mid && j<=end;i++,j++){
			int t = a[i];
			a[i] = a[j];
			a[j] = t;
		}

		i = start;
		j = mid + 1;
		while(i <= mid && j <= end){
			if(a[i] <= a[j])
				i++;
			else{
				othr += mid + 1 - i;
				j++;
			}
		}

		inv[size] += inve;
		other[size] += othr;

		for(int x=0;x<k;x++)
			a[start + x] = temp[x];

	}
}

class InputReader4 {

	private InputStream stream;
	private byte[] buf = new byte[1024];
	private int curChar;
	private int numChars;
	private SpaceCharFilter filter;
	public InputReader4(InputStream stream) {
		this.stream = stream;
	}

	public int snext() {
		if (numChars == -1)
			throw new InputMismatchException();
		if (curChar >= numChars) {
			curChar = 0;
			try {
				numChars = stream.read(buf);
			} catch (IOException e) {
				throw new InputMismatchException();
			}
			if (numChars <= 0)
				return -1;
		}
		return buf[curChar++];
	}

	public int nextInt() {
		int c = snext();
		while (isSpaceChar(c))
			c = snext();
		int sgn = 1;
		if (c == '-') {
			sgn = -1;
			c = snext();
		}

		int res = 0;

		do {
			if (c < '0' || c > '9')
				throw new InputMismatchException();
			res *= 10;
			res += c - '0';
			c = snext();
		} while (!isSpaceChar(c));

		return res * sgn;
	}

	public boolean isSpaceChar(int c) {
		if (filter != null)
			return filter.isSpaceChar(c);
		return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
	}

	public interface SpaceCharFilter {
		public boolean isSpaceChar(int ch);
	}
}


import java.io.InputStreamReader;
import java.io.IOException;
import java.util.InputMismatchException;
import java.io.BufferedReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskC solver = new TaskC();
        solver.solve(1, in, out);
        out.close();
    }
}

class TaskC {
    public void solve(int testNumber, InputReader in, PrintWriter out) {
        int n = in.nextInt();
        int []a = new int[1 << n];
        for (int i = 0; i < a.length; ++i) {
            a[i] = in.nextInt();
        }

        inv = new long[n + 1];
        ord = new long[n + 1];
        mergeSort(a, 0, a.length);

        int m = in.nextInt();
        for (int i = 0; i < m; ++i) {
            int q = in.nextInt();
            for (int t = 0; t <= q; ++t) {
                long temp = inv[t];
                inv[t] = ord[t];
                ord[t] = temp;
            }
            long res = 0;
            for (int t = 0; t <= n; ++t) {
                res += inv[t];
            }
            out.println(res);
        }
    }

    void mergeSort(int []a, int begin, int end) {
        if (end - begin == 1) {
            return;
        }
        int mid = (begin + end) / 2;
        mergeSort(a, begin, mid);
        mergeSort(a, mid, end);

        int level = 0;
        while ((1 << level) < end - begin) ++level;

        // Count inversions.
        for (int i = begin, j = mid; i < mid && j < end;) {
            if (a[i] <= a[j]) {
                ++i;
            } else {
                inv[level] += mid - i;
                ++j;
            }
        }

        // Count orders.
        for (int i = begin, j = mid; i < mid && j < end;) {
            if (a[i] < a[j]) {
                ord[level] += end - j;
                ++i;
            } else {
                ++j;
            }
        }

        // Merge.
        int []b = new int[end - begin];
        int size = 0, i = begin, j = mid;
        while (i < mid && j < end) {
            if (a[i] <= a[j]) {
                b[size++] = a[i++];
            } else {
                b[size++] = a[j++];
            }
        }
        while (i < mid) b[size++] = a[i++];
        while (j < end) b[size++] = a[j++];
        for (int t = 0; t < size; ++t) {
            a[begin + t] = b[t];
        }
    }

    long []inv;
    long []ord;
}

class InputReader {
    BufferedReader bufReader;
    StringTokenizer stringTokenizer;

    public InputReader(InputStream stream) {
        bufReader = new BufferedReader(new InputStreamReader(stream));
    }

    String nextString() {
        while (stringTokenizer == null || !stringTokenizer.hasMoreTokens()) {
            try {
                String line = bufReader.readLine();
                if (line == null) {
                    return null;
                }
                stringTokenizer = new StringTokenizer(line);
            } catch (IOException e) {
                throw new InputMismatchException();
            }
        }
        return stringTokenizer.nextToken();
    }

    public int nextInt() {
        return Integer.parseInt(nextString());
    }

    }


import java.io.InputStreamReader;
import java.io.IOException;
import java.util.InputMismatchException;
import java.io.PrintStream;
import java.io.BufferedReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskC solver = new TaskC();
        solver.solve(1, in, out);
        out.close();
    }
}

class TaskC {
    public void solve(int testNumber, InputReader in, PrintWriter out) {
        int n = in.nextInt();
        int []a = new int[1 << n];
        for (int i = 0; i < a.length; ++i) {
            a[i] = in.nextInt();
        }

        inv = new long[n + 1];
        ord = new long[n + 1];
        mergeSort(a, 0, a.length);

        debug();

        int m = in.nextInt();
        for (int i = 0; i < m; ++i) {
            int q = in.nextInt();
            for (int t = 0; t <= q; ++t) {
                long temp = inv[t];
                inv[t] = ord[t];
                ord[t] = temp;
            }
            debug();
            long res = 0;
            for (int t = 0; t <= n; ++t) {
                res += inv[t];
            }
            out.println(res);
        }
    }

    void debug() {
        for (int i = 0; i < inv.length; ++i) {
            System.err.printf("%d ", inv[i]);
        }
        System.err.println();
        for (int i = 0; i < ord.length; ++i) {
            System.err.printf("%d ", ord[i]);
        }
        System.err.println();
        System.err.println();
    }

    void mergeSort(int []a, int begin, int end) {
        if (end - begin == 1) {
            return;
        }
        int mid = (begin + end) / 2;
        mergeSort(a, begin, mid);
        mergeSort(a, mid, end);

        int level = 0;
        while ((1 << level) < end - begin) ++level;

        // Count inversions.
        for (int i = begin, j = mid; i < mid && j < end;) {
            if (a[i] <= a[j]) {
                ++i;
            } else {
                inv[level] += mid - i;
                ++j;
            }
        }

        // Count orders.
        for (int i = begin, j = mid; i < mid && j < end;) {
            if (a[i] < a[j]) {
                ord[level] += end - j;
                ++i;
            } else {
                ++j;
            }
        }

        // Merge.
        int []b = new int[end - begin];
        int size = 0, i = begin, j = mid;
        while (i < mid && j < end) {
            if (a[i] <= a[j]) {
                b[size++] = a[i++];
            } else {
                b[size++] = a[j++];
            }
        }
        while (i < mid) b[size++] = a[i++];
        while (j < end) b[size++] = a[j++];
        for (int t = 0; t < size; ++t) {
            a[begin + t] = b[t];
        }
    }

    long []inv;
    long []ord;
}

class InputReader {
    BufferedReader bufReader;
    StringTokenizer stringTokenizer;

    public InputReader(InputStream stream) {
        bufReader = new BufferedReader(new InputStreamReader(stream));
    }

    String nextString() {
        while (stringTokenizer == null || !stringTokenizer.hasMoreTokens()) {
            try {
                String line = bufReader.readLine();
                if (line == null) {
                    return null;
                }
                stringTokenizer = new StringTokenizer(line);
            } catch (IOException e) {
                throw new InputMismatchException();
            }
        }
        return stringTokenizer.nextToken();
    }

    public int nextInt() {
        String s = nextString();
        return Integer.parseInt(s);
    }

    }


import java.io.InputStreamReader;
import java.io.IOException;
import java.util.InputMismatchException;
import java.io.PrintStream;
import java.io.BufferedReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskC solver = new TaskC();
        solver.solve(1, in, out);
        out.close();
    }
}

class TaskC {
    public void solve(int testNumber, InputReader in, PrintWriter out) {
        int n = in.nextInt();
        int []a = new int[1 << n];
        for (int i = 0; i < a.length; ++i) {
            a[i] = in.nextInt();
        }

        inv = new long[n + 1];
        ord = new long[n + 1];
        mergeSort(a, 0, a.length);

        debug();

        int m = in.nextInt();
        for (int i = 0; i < m; ++i) {
            int q = in.nextInt();
            for (int t = 0; t <= q; ++t) {
                long temp = inv[t];
                inv[t] = ord[t];
                ord[t] = temp;
            }
            debug();
            long res = 0;
            for (int t = 0; t <= n; ++t) {
                res += inv[t];
            }
            out.println(res);
        }
    }

    void debug() {

    }

    void mergeSort(int []a, int begin, int end) {
        if (end - begin == 1) {
            return;
        }
        int mid = (begin + end) / 2;
        mergeSort(a, begin, mid);
        mergeSort(a, mid, end);

        int level = 0;
        while ((1 << level) < end - begin) ++level;

        // Count inversions.
        for (int i = begin, j = mid; i < mid && j < end;) {
            if (a[i] <= a[j]) {
                ++i;
            } else {
                inv[level] += mid - i;
                ++j;
            }
        }

        // Count orders.
        for (int i = begin, j = mid; i < mid && j < end;) {
            if (a[i] < a[j]) {
                ord[level] += end - j;
                ++i;
            } else {
                ++j;
            }
        }

        // Merge.
        int []b = new int[end - begin];
        int size = 0, i = begin, j = mid;
        while (i < mid && j < end) {
            if (a[i] <= a[j]) {
                b[size++] = a[i++];
            } else {
                b[size++] = a[j++];
            }
        }
        while (i < mid) b[size++] = a[i++];
        while (j < end) b[size++] = a[j++];
        for (int t = 0; t < size; ++t) {
            a[begin + t] = b[t];
        }
    }

    long []inv;
    long []ord;
}

class InputReader {
    BufferedReader bufReader;
    StringTokenizer stringTokenizer;

    public InputReader(InputStream stream) {
        bufReader = new BufferedReader(new InputStreamReader(stream));
    }

    String nextString() {
        while (stringTokenizer == null || !stringTokenizer.hasMoreTokens()) {
            try {
                String line = bufReader.readLine();
                if (line == null) {
                    return null;
                }
                stringTokenizer = new StringTokenizer(line);
            } catch (IOException e) {
                throw new InputMismatchException();
            }
        }
        return stringTokenizer.nextToken();
    }

    public int nextInt() {
        String s = nextString();
        return Integer.parseInt(s);
    }

    }


#include <stdio.h>
#include <algorithm>
int n;
int A[200010];
double a[200010],b[200010],c[200010];
double lo,hi;
double ans = 2e10+1.0;
double min(double a,double b){
    return a<b?a:b;
}
double max(double a,double b){
    return a>b?a:b;
}
double abs(double a){
    return a>0?a:-a;
}
double f(){
    bool minusExist=false,plusExist=false;
    double s1=0,s2=0;
    double ret1=2e10,ret2=-2e10;
    for(int i=1;i<=n;i++){
        if(b[i]<0) minusExist = true;
        if(b[i]>0) plusExist = true;
    }
    if(minusExist){
        for(int i=1;i<=n;i++){
            s1+=b[i];
            if(s1>0) s1 = 0;
            if(ret1>s1) ret1 = s1;
        }
    }
    else{
        ret1 = 0;
    }
    if(plusExist){
        for(int i=n;i>=1;i--){
            s2+=b[i];
            if(s2<0) s2 = 0;
            if(ret2<s2) ret2 = s2;
        }
    }
    else{
        ret2 = 0;
    }
    return max(abs(ret1),abs(ret2));
}
double g(){
    bool minusExist=false,plusExist=false;
    double s1=0,s2=0;
    double ret1=2e10,ret2=-2e10;
    for(int i=1;i<=n;i++){
        if(c[i]<0) minusExist = true;
        if(c[i]>0) plusExist = true;
    }
    if(minusExist){
        for(int i=1;i<=n;i++){
            s1+=c[i];
            if(s1>0) s1 = 0;
            if(ret1>s1) ret1 = s1;
        }
    }
    else{
        ret1 = 0;
    }
    if(plusExist){
        for(int i=n;i>=1;i--){
            s2+=c[i];
            if(s2<0) s2 = 0;
            if(ret2<s2) ret2 = s2;
        }
    }
    else{
        ret2 = 0;
    }
    return max(abs(ret1),abs(ret2));
}
int main(){
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        scanf("%d",&A[i]);
        a[i] = A[i];
    }
    lo = -10100.0;
    hi = 10100.0;
    while((hi-lo)>1e-10){
        double me1 = lo+(hi-lo)/3.0;
        double me2 = hi-(hi-lo)/3.0;
        for(int i=1;i<=n;i++){
            b[i] = a[i]-me1;
            c[i] = a[i]-me2;
        }
        double res1 = f();
        double res2 = g();
        ans = min(ans,min(res1,res2));
        if(res1<res2){
            hi = me2;
        }
        else{
            lo = me1;
        }
    }
    printf("%.9lf",ans);
}


#include <stdio.h>
#include <algorithm>
int n;
double a[200010],b[200010],c[200010];
double lo,hi;
double max(double a,double b){
    return a>b?a:b;
}
double abs(double a){
    return a>0?a:-a;
}
double f(){
    double s1=0,s2=0;
    double ret1=987654321.0,ret2=-987654321.0;
    for(int i=1;i<=n;i++){
        s1+=b[i];
        if(s1>0) s1 = 0;
        if(ret1>s1) ret1 = s1;
    }
    for(int i=n;i>=1;i--){
        s2+=b[i];
        if(s2<0) s2 = 0;
        if(ret2<s2) ret2 = s2;
    }
    return max(abs(ret1),abs(ret2));
}
double g(){
    double s1=0,s2=0;
    double ret1=987654321.0,ret2=-987654321.0;
    for(int i=1;i<=n;i++){
        s1+=c[i];
        if(s1>0) s1 = 0;
        if(ret1>s1) ret1 = s1;
    }
    for(int i=n;i>=1;i--){
        s2+=c[i];
        if(s2<0) s2 = 0;
        if(ret2<s2) ret2 = s2;
    }
    return max(abs(ret1),abs(ret2));
}
double h(double x){
    double s1=0,s2=0;
    double ret1=987654321.0,ret2=-987654321.0;
    for(int i=1;i<=n;i++){
        a[i]-=x;
    }
    for(int i=1;i<=n;i++){
        s1+=a[i];
        if(s1>0) s1 = 0;
        if(ret1>s1) ret1 = s1;
    }
    for(int i=n;i>=1;i--){
        s2+=a[i];
        if(s2<0) s2 = 0;
        if(ret2<s2) ret2 = s2;
    }
    return max(abs(ret1),abs(ret2));
}
int main(){
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        scanf("%lf",&a[i]);
    }
    lo = -1000000.0;
    hi = 1000000.0;
    while(hi-lo>1e-9){
        double me1 = lo+(hi-lo)/3.0;
        double me2 = hi-(hi-lo)/3.0;
        for(int i=1;i<=n;i++){
            b[i] = a[i]-me1;
            c[i] = a[i]-me2;
        }
        double res1 = f();
        double res2 = g();
        if(res1<res2){
            hi = me2;
        }
        else{
            lo = me1;
        }
    }
    double ans = h(lo);
    printf("%.9lf",ans);
}


#include <stdio.h>
#include <algorithm>
int n;
double a[200010],b[200010],c[200010];
double lo,hi;
double max(double a,double b){
    return a>b?a:b;
}
double abs(double a){
    return a>0?a:-a;
}
double f(){
    double s1=0,s2=0;
    double ret1=2e10,ret2=-2e10;
    for(int i=1;i<=n;i++){
        s1+=b[i];
        if(s1>0) s1 = 0;
        if(ret1>s1) ret1 = s1;
    }
    for(int i=n;i>=1;i--){
        s2+=b[i];
        if(s2<0) s2 = 0;
        if(ret2<s2) ret2 = s2;
    }
    return max(abs(ret1),abs(ret2));
}
double g(){
    double s1=0,s2=0;
    double ret1=2e10,ret2=-2e10;
    for(int i=1;i<=n;i++){
        s1+=c[i];
        if(s1>0) s1 = 0;
        if(ret1>s1) ret1 = s1;
    }
    for(int i=n;i>=1;i--){
        s2+=c[i];
        if(s2<0) s2 = 0;
        if(ret2<s2) ret2 = s2;
    }
    return max(abs(ret1),abs(ret2));
}
double h(double x){
    double s1=0,s2=0;
    double ret1=2e9+1.0,ret2=-2e9-1.0;
    for(int i=1;i<=n;i++){
        a[i]-=x;
    }
    for(int i=1;i<=n;i++){
        s1+=a[i];
        if(s1>0) s1 = 0;
        if(ret1>s1) ret1 = s1;
    }
    for(int i=n;i>=1;i--){
        s2+=a[i];
        if(s2<0) s2 = 0;
        if(ret2<s2) ret2 = s2;
    }
    return max(abs(ret1),abs(ret2));
}
int main(){
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        scanf("%lf",&a[i]);
    }
    lo = -1000100.0;
    hi = 1000100.0;
    while(hi-lo>1e-10){
        //printf("%.9lf %.9lf\n",lo,hi);
        double me1 = lo+(hi-lo)/3.0;
        double me2 = hi-(hi-lo)/3.0;
        for(int i=1;i<=n;i++){
            b[i] = a[i]-me1;
            c[i] = a[i]-me2;
        }
        double res1 = f();
        double res2 = g();
        if(res1<=res2){
            hi = me2;
        }
        else{
            lo = me1;
        }
    }
    double ans = h(lo);
    printf("%.9lf",ans);
}


#include <stdio.h>
#include <algorithm>
int n;
double a[200010],b[200010],c[200010];
double lo,hi;
double max(double a,double b){
    return a>b?a:b;
}
double abs(double a){
    return a>0?a:-a;
}
double f(){
    double s1=0,s2=0;
    double ret1=2e10,ret2=-2e10;
    for(int i=1;i<=n;i++){
        s1+=b[i];
        if(s1>0) s1 = 0;
        if(ret1>s1) ret1 = s1;
    }
    for(int i=n;i>=1;i--){
        s2+=b[i];
        if(s2<0) s2 = 0;
        if(ret2<s2) ret2 = s2;
    }
    return max(abs(ret1),abs(ret2));
}
double g(){
    double s1=0,s2=0;
    double ret1=2e10,ret2=-2e10;
    for(int i=1;i<=n;i++){
        s1+=c[i];
        if(s1>0) s1 = 0;
        if(ret1>s1) ret1 = s1;
    }
    for(int i=n;i>=1;i--){
        s2+=c[i];
        if(s2<0) s2 = 0;
        if(ret2<s2) ret2 = s2;
    }
    return max(abs(ret1),abs(ret2));
}
double h(double x){
    double s1=0,s2=0;
    double ret1=2e9+1.0,ret2=-2e9-1.0;
    for(int i=1;i<=n;i++){
        a[i]-=x;
    }
    for(int i=1;i<=n;i++){
        s1+=a[i];
        if(s1>0) s1 = 0;
        if(ret1>s1) ret1 = s1;
    }
    for(int i=n;i>=1;i--){
        s2+=a[i];
        if(s2<0) s2 = 0;
        if(ret2<s2) ret2 = s2;
    }
    return max(abs(ret1),abs(ret2));
}
int main(){
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        scanf("%lf",&a[i]);
    }
    lo = -1000100.0;
    hi = 1000100.0;
    while(hi-lo>1e-10){
        printf("%.9lf %.9lf\n",lo,hi);
        double me1 = lo+(hi-lo)/3.0;
        double me2 = hi-(hi-lo)/3.0;
        for(int i=1;i<=n;i++){
            b[i] = a[i]-me1;
            c[i] = a[i]-me2;
        }
        double res1 = f();
        double res2 = g();
        if(res1<=res2){
            hi = me2;
        }
        else{
            lo = me1;
        }
    }
    double ans = h(lo);
    printf("%.9lf",ans);
}


#include <stdio.h>
#include <algorithm>
int n;
int A[200010];
long double a[200010],b[200010],c[200010];
long double lo,hi;
long double ans = 2e10+1.0;
long double min(long double a,long double b){
    return a<b?a:b;
}
long double max(long double a,long double b){
    return a>b?a:b;
}
long double abs(long double a){
    return a>0?a:-a;
}
long double f(){
    bool minusExist=false,plusExist=false;
    long double s1=0,s2=0;
    long double ret1=2e10+1,ret2=-2e10-1;
    for(int i=1;i<=n;i++){
        if(b[i]<0) minusExist = true;
        if(b[i]>0) plusExist = true;
    }
    if(minusExist){
        for(int i=1;i<=n;i++){
            s1+=b[i];
            if(s1>0) s1 = 0;
            if(ret1>s1) ret1 = s1;
        }
    }
    else{
        ret1 = 0;
    }
    if(plusExist){
        for(int i=n;i>=1;i--){
            s2+=b[i];
            if(s2<0) s2 = 0;
            if(ret2<s2) ret2 = s2;
        }
    }
    else{
        ret2 = 0;
    }
    return max(abs(ret1),abs(ret2));
}
long double g(){
    bool minusExist=false,plusExist=false;
    long double s1=0,s2=0;
    long double ret1=2e10+1,ret2=-2e10-1;
    for(int i=1;i<=n;i++){
        if(c[i]<0) minusExist = true;
        if(c[i]>0) plusExist = true;
    }
    if(minusExist){
        for(int i=1;i<=n;i++){
            s1+=c[i];
            if(s1>0) s1 = 0;
            if(ret1>s1) ret1 = s1;
        }
    }
    else{
        ret1 = 0;
    }
    if(plusExist){
        for(int i=n;i>=1;i--){
            s2+=c[i];
            if(s2<0) s2 = 0;
            if(ret2<s2) ret2 = s2;
        }
    }
    else{
        ret2 = 0;
    }
    return max(abs(ret1),abs(ret2));
}
int main(){
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        scanf("%d",&A[i]);
        a[i] = A[i];
    }
    lo = -10100.0;
    hi = 10100.0;
    while((hi-lo)>1e-10){
        long double me1 = lo+(hi-lo)/3.0;
        long double me2 = hi-(hi-lo)/3.0;
        for(int i=1;i<=n;i++){
            b[i] = a[i]-me1;
            c[i] = a[i]-me2;
        }
        long double res1 = f();
        long double res2 = g();
        ans = min(ans,min(res1,res2));
        if(res1<res2){
            hi = me2;
        }
        else{
            lo = me1;
        }
    }
    printf("%.9lf",(double)ans);
}


#include <stdio.h>
#include <algorithm>
int n;
double a[200010],b[200010],c[200010];
double lo,hi;
double max(double a,double b){
    return a>b?a:b;
}
double abs(double a){
    return a>0?a:-a;
}
double f(){
    double s1=0,s2=0;
    double ret1=2e10,ret2=-2e10;
    for(int i=1;i<=n;i++){
        s1+=b[i];
        if(s1>0) s1 = 0;
        if(ret1>s1) ret1 = s1;
    }
    for(int i=n;i>=1;i--){
        s2+=b[i];
        if(s2<0) s2 = 0;
        if(ret2<s2) ret2 = s2;
    }
    return max(abs(ret1),abs(ret2));
}
double g(){
    double s1=0,s2=0;
    double ret1=2e10,ret2=-2e10;
    for(int i=1;i<=n;i++){
        s1+=c[i];
        if(s1>0) s1 = 0;
        if(ret1>s1) ret1 = s1;
    }
    for(int i=n;i>=1;i--){
        s2+=c[i];
        if(s2<0) s2 = 0;
        if(ret2<s2) ret2 = s2;
    }
    return max(abs(ret1),abs(ret2));
}
double h(double x){
    double s1=0,s2=0;
    double ret1=2e10,ret2=-2e10;
    for(int i=1;i<=n;i++){
        a[i]-=x;
    }
    for(int i=1;i<=n;i++){
        s1+=a[i];
        if(s1>0) s1 = 0;
        if(ret1>s1) ret1 = s1;
    }
    for(int i=n;i>=1;i--){
        s2+=a[i];
        if(s2<0) s2 = 0;
        if(ret2<s2) ret2 = s2;
    }
    return max(abs(ret1),abs(ret2));
}
int main(){
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        scanf("%lf",&a[i]);
    }
    lo = -1000100.0;
    hi = 1000100.0;
    while(hi-lo>1e-10){
        //printf("%.9lf %.9lf\n",lo,hi);
        double me1 = lo+(hi-lo)/3.0;
        double me2 = hi-(hi-lo)/3.0;
        for(int i=1;i<=n;i++){
            b[i] = a[i]-me1;
            c[i] = a[i]-me2;
        }
        double res1 = f();
        double res2 = g();
        if(res1<=res2){
            hi = me2;
        }
        else{
            lo = me1;
        }
    }
    double ans = h(lo);
    printf("%.9lf",ans);
}


#include <stdio.h>
#include <algorithm>
int n;
double a[200010],b[200010],c[200010];
double lo,hi;
double max(double a,double b){
    return a>b?a:b;
}
double abs(double a){
    return a>0?a:-a;
}
double f(){
    double s1=0,s2=0;
    double ret1=987654321.0,ret2=-987654321.0;
    for(int i=1;i<=n;i++){
        s1+=b[i];
        if(s1>0) s1 = 0;
        if(ret1>s1) ret1 = s1;
    }
    for(int i=n;i>=1;i--){
        s2+=b[i];
        if(s2<0) s2 = 0;
        if(ret2<s2) ret2 = s2;
    }
    return max(abs(ret1),abs(ret2));
}
double g(){
    double s1=0,s2=0;
    double ret1=987654321.0,ret2=-987654321.0;
    for(int i=1;i<=n;i++){
        s1+=c[i];
        if(s1>0) s1 = 0;
        if(ret1>s1) ret1 = s1;
    }
    for(int i=n;i>=1;i--){
        s2+=c[i];
        if(s2<0) s2 = 0;
        if(ret2<s2) ret2 = s2;
    }
    return max(abs(ret1),abs(ret2));
}
double h(double x){
    double s1=0,s2=0;
    double ret1=987654321.0,ret2=-987654321.0;
    for(int i=1;i<=n;i++){
        a[i]-=x;
    }
    for(int i=1;i<=n;i++){
        s1+=a[i];
        if(s1>0) s1 = 0;
        if(ret1>s1) ret1 = s1;
    }
    for(int i=n;i>=1;i--){
        s2+=a[i];
        if(s2<0) s2 = 0;
        if(ret2<s2) ret2 = s2;
    }
    return max(abs(ret1),abs(ret2));
}
int main(){
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        scanf("%lf",&a[i]);
    }
    lo = -10000.0;
    hi = 10000.0;
    while(hi-lo>1e-9){
        double me1 = lo+(hi-lo)/3.0;
        double me2 = hi-(hi-lo)/3.0;
        for(int i=1;i<=n;i++){
            b[i] = a[i]-me1;
            c[i] = a[i]-me2;
        }
        double res1 = f();
        double res2 = g();
        if(res1<res2){
            hi = me2;
        }
        else{
            lo = me1;
        }
    }
    double ans = h(lo);
    printf("%.9lf",ans);
}


#include <stdio.h>
int n;
int A[200010];
long double a[200010],b[200010],c[200010];
long double lo,hi;
long double ans = 2e10+1.0;
long double min(long double a,long double b){
    return a<b?a:b;
}
long double max(long double a,long double b){
    return a>b?a:b;
}
long double abs(long double a){
    return a>0?a:-a;
}
long double f(){
    bool minusExist=false,plusExist=false;
    long double s1=0,s2=0;
    long double ret1=2e10+1,ret2=-2e10-1;
    for(int i=1;i<=n;i++){
        if(b[i]<0) minusExist = true;
        if(b[i]>0) plusExist = true;
    }
    if(minusExist){
        for(int i=1;i<=n;i++){
            s1+=b[i];
            if(s1>0) s1 = 0;
            else if(ret1>s1) ret1 = s1;
        }
    }
    else{
        ret1 = 0;
    }
    if(plusExist){
        for(int i=1;i<=n;i++){
            s2+=b[i];
            if(s2<0) s2 = 0;
            else if(ret2<s2) ret2 = s2;
        }
    }
    else{
        ret2 = 0;
    }
    return max(abs(ret1),abs(ret2));
}
long double g(){
    bool minusExist=false,plusExist=false;
    long double s1=0,s2=0;
    long double ret1=2e10+1,ret2=-2e10-1;
    for(int i=1;i<=n;i++){
        if(c[i]<0) minusExist = true;
        if(c[i]>0) plusExist = true;
    }
    if(minusExist){
        for(int i=1;i<=n;i++){
            s1+=c[i];
            if(s1>0) s1 = 0;
            else if(ret1>s1) ret1 = s1;
        }
    }
    else{
        ret1 = 0;
    }
    if(plusExist){
        for(int i=1;i<=n;i++){
            s2+=c[i];
            if(s2<0) s2 = 0;
            else if(ret2<s2) ret2 = s2;
        }
    }
    else{
        ret2 = 0;
    }
    return max(abs(ret1),abs(ret2));
}
int main(){
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        scanf("%d",&A[i]);
        a[i] = A[i];
    }
    lo = -10100.0;
    hi = 10100.0;
    while((hi-lo)>1e-10){
        long double me1 = lo+(hi-lo)/3.0;
        long double me2 = hi-(hi-lo)/3.0;
        for(int i=1;i<=n;i++){
            b[i] = a[i]-me1;
            c[i] = a[i]-me2;
        }
        long double res1 = f();
        long double res2 = g();
        ans = min(ans,min(res1,res2));
        if(res1<res2){
            hi = me2;
        }
        else{
            lo = me1;
        }
    }
    printf("%.9lf",(double)ans);
}


#include <stdio.h>
#include <iostream>
int n;
int A[200010];
long double a[200010],b[200010],c[200010];
long double lo,hi;
long double ans = 2e10+1.0;
long double min(long double a,long double b){
    return a<b?a:b;
}
long double max(long double a,long double b){
    return a>b?a:b;
}
long double abs(long double a){
    return a>0?a:-a;
}
long double f(){
    bool minusExist=false,plusExist=false;
    long double s1=0,s2=0;
    long double ret1=2e10+1,ret2=-2e10-1;
    for(int i=1;i<=n;i++){
        if(b[i]<0) minusExist = true;
        if(b[i]>0) plusExist = true;
    }
    if(minusExist){
        for(int i=1;i<=n;i++){
            s1+=b[i];
            if(s1>0) s1 = 0;
            else if(ret1>s1) ret1 = s1;
        }
    }
    else{
        ret1 = 0;
    }
    if(plusExist){
        for(int i=1;i<=n;i++){
            s2+=b[i];
            if(s2<0) s2 = 0;
            else if(ret2<s2) ret2 = s2;
        }
    }
    else{
        ret2 = 0;
    }
    return max(abs(ret1),abs(ret2));
}
long double g(){
    bool minusExist=false,plusExist=false;
    long double s1=0,s2=0;
    long double ret1=2e10+1,ret2=-2e10-1;
    for(int i=1;i<=n;i++){
        if(c[i]<0) minusExist = true;
        if(c[i]>0) plusExist = true;
    }
    if(minusExist){
        for(int i=1;i<=n;i++){
            s1+=c[i];
            if(s1>0) s1 = 0;
            else if(ret1>s1) ret1 = s1;
        }
    }
    else{
        ret1 = 0;
    }
    if(plusExist){
        for(int i=1;i<=n;i++){
            s2+=c[i];
            if(s2<0) s2 = 0;
            else if(ret2<s2) ret2 = s2;
        }
    }
    else{
        ret2 = 0;
    }
    return max(abs(ret1),abs(ret2));
}
int main(){
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        scanf("%d",&A[i]);
        a[i] = A[i];
    }
    lo = -10100.0;
    hi = 10100.0;
    for(int i=1;i<=500;i++){
        long double me1 = lo+(hi-lo)/3.0;
        long double me2 = hi-(hi-lo)/3.0;
        for(int i=1;i<=n;i++){
            b[i] = a[i]+me1;
            c[i] = a[i]+me2;
        }
        long double res1 = f();
        long double res2 = g();
        ans = min(ans,min(res1,res2));
        if(res1<res2){
            hi = me2;
        }
        else{
            lo = me1;
        }
    }
    std::cout.precision(9);
    std::cout<<ans;
    //printf("%.12lf",(double)ans);
}


#include <stdio.h>
#include <algorithm>
int n;
double a[200010],b[200010],c[200010];
double lo,hi;
double ans = 2e10+1.0;
double min(double a,double b){
    return a<b?a:b;
}
double max(double a,double b){
    return a>b?a:b;
}
double abs(double a){
    return a>0?a:-a;
}
double f(){
    bool minusExist=false,plusExist=false;
    double s1=0,s2=0;
    double ret1=2e10,ret2=-2e10;
    for(int i=1;i<=n;i++){
        if(b[i]<0) minusExist = true;
        else plusExist = true;
    }
    if(minusExist){
        for(int i=1;i<=n;i++){
            s1+=b[i];
            if(s1>0) s1 = 0;
            if(ret1>s1) ret1 = s1;
        }
    }
    else if(plusExist){
        for(int i=n;i>=1;i--){
            s2+=b[i];
            if(s2<0) s2 = 0;
            if(ret2<s2) ret2 = s2;
        }
    }
    return max(abs(ret1),abs(ret2));
}
double g(){
    bool minusExist=false,plusExist=false;
    double s1=0,s2=0;
    double ret1=2e10,ret2=-2e10;
    for(int i=1;i<=n;i++){
        if(c[i]<0) minusExist = true;
        else plusExist = true;
    }
    if(minusExist){
        for(int i=1;i<=n;i++){
            s1+=c[i];
            if(s1>0) s1 = 0;
            if(ret1>s1) ret1 = s1;
        }
    }
    else if(plusExist){
        for(int i=n;i>=1;i--){
            s2+=c[i];
            if(s2<0) s2 = 0;
            if(ret2<s2) ret2 = s2;
        }
    }
    return max(abs(ret1),abs(ret2));
}
double h(double x){
    double s1=0,s2=0;
    double ret1=2e10,ret2=-2e10;
    bool minusExist=false,plusExist=false;
    for(int i=1;i<=n;i++){
        a[i]-=x;
    }
    for(int i=1;i<=n;i++){
        if(a[i]<0) minusExist = true;
        else plusExist = true;
    }
    if(minusExist){
        for(int i=1;i<=n;i++){
            s1+=a[i];
            if(s1>0) s1 = 0;
            if(ret1>s1) ret1 = s1;
        }
    }
    else if(plusExist){
        for(int i=n;i>=1;i--){
            s2+=a[i];
            if(s2<0) s2 = 0;
            if(ret2<s2) ret2 = s2;
        }
    }
    return max(abs(ret1),abs(ret2));
}
int main(){
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        scanf("%lf",&a[i]);
    }
    lo = -10100.0;
    hi = 10100.0;
    while((hi-lo)>1e-10){
        double me1 = lo+(hi-lo)/3.0;
        double me2 = hi-(hi-lo)/3.0;
        for(int i=1;i<=n;i++){
            b[i] = a[i]-me1;
            c[i] = a[i]-me2;
        }
        double res1 = f();
        double res2 = g();
        ans = min(ans,min(res1,res2));
        if(res1<res2){
            hi = me2;
        }
        else{
            lo = me1;
        }
    }
    printf("%.9lf",ans);
}