You are given an array a of length 2^n. You should process q queries on it. Each query has one of the following 4 types: 

  1. Replace(x, k) — change a_x to k; 
  2. Reverse(k) — reverse each subarray [(i-1) ⋅ 2^k+1, i ⋅ 2^k] for all i (i ≥ 1); 
  3. Swap(k) — swap subarrays [(2i-2) ⋅ 2^k+1, (2i-1) ⋅ 2^k] and [(2i-1) ⋅ 2^k+1, 2i ⋅ 2^k] for all i (i ≥ 1); 
  4. Sum(l, r) — print the sum of the elements of subarray [l, r]. 



Write a program that can quickly process given queries.

Input

The first line contains two integers n, q (0 ≤ n ≤ 18; 1 ≤ q ≤ 10^5) — the length of array a and the number of queries.

The second line contains 2^n integers a_1, a_2, …, a_{2^n} (0 ≤ a_i ≤ 10^9).

Next q lines contains queries — one per line. Each query has one of 4 types: 

  * "1 x k" (1 ≤ x ≤ 2^n; 0 ≤ k ≤ 10^9) — Replace(x, k); 
  * "2 k" (0 ≤ k ≤ n) — Reverse(k); 
  * "3 k" (0 ≤ k < n) — Swap(k); 
  * "4 l r" (1 ≤ l ≤ r ≤ 2^n) — Sum(l, r). 



It is guaranteed that there is at least one Sum query.

Output

Print the answer for each Sum query.

Examples

Input


2 3
7 4 9 9
1 2 8
3 1
4 2 4


Output


24


Input


3 8
7 0 8 8 7 1 5 2
4 3 7
2 1
3 2
4 1 6
2 3
1 5 16
4 8 8
3 0


Output


29
22
1

Note

In the first sample, initially, the array a is equal to \{7,4,9,9\}.

After processing the first query. the array a becomes \{7,8,9,9\}.

After processing the second query, the array a_i becomes \{9,9,7,8\}

Therefore, the answer to the third query is 9+7+8=24.

In the second sample, initially, the array a is equal to \{7,0,8,8,7,1,5,2\}. What happens next is: 

  1. Sum(3, 7) → 8 + 8 + 7 + 1 + 5 = 29; 
  2. Reverse(1) → \{0,7,8,8,1,7,2,5\}; 
  3. Swap(2) → \{1,7,2,5,0,7,8,8\}; 
  4. Sum(1, 6) → 1 + 7 + 2 + 5 + 0 + 7 = 22; 
  5. Reverse(3) → \{8,8,7,0,5,2,7,1\}; 
  6. Replace(5, 16) → \{8,8,7,0,16,2,7,1\}; 
  7. Sum(8, 8) → 1; 
  8. Swap(0) → \{8,8,0,7,2,16,1,7\}. 
import java.io.*;
import java.util.*;

public class Solution {
static class SegmentTree{
	
	int left, right, level;
	// lChild => tree[2*tn] , rChild => tree[2*tn+1]
	SegmentTree lChild, rChild; 
	long sum;
	long lazyForSum = 0;
	int lazyForSwap = -1; // tells how many levels below swap has to be done
	int lazyForReverse = -1;
	int lazyIndex = 0;
	public SegmentTree(int[]arr, int left, int right, int level) {
		this.left = left;
		this.right = right;
		this.level = level;
		if(left == right) { // LEAF NODE
			this.sum = arr[left];
		}
		else {
			int mid = (left + right) >> 1;
			lChild = new SegmentTree(arr, left, mid, level-1);
			rChild = new SegmentTree(arr, mid + 1, right,level-1);
			recalculate();
		}
//		out.println("level for " + left + " to " + right + " = " + this.level);
	}
	public SegmentTree lChild() {
		return !flipped[level] ? lChild : rChild;
	}
	public SegmentTree rChild() {
		return flipped[level] ? lChild : rChild;
	}
	public void printTree() {
//		updateLazy();
//		out.println("left = " + left + " right = " + right + " level = " + level + " sum = " + sum);
		if(left == right)return;
		lChild.printTree();
		rChild.printTree();
	}
	public void recalculate() { // BASICALLY DOING tree[tn] = tree[2*tn] + tree[2*tn]
		if(left == right)return;
		this.sum = lChild.sum + rChild.sum;
	}
	
	public void pointUpdate(int index, int value) { // point update of type SET TO
		updateLazy();
		if(left == right) {
			this.sum = value;
		}else {
			if(index < 1<<(level-1)) {
				lChild().pointUpdate(index, value);
			}else {
				index -= (1<<(level-1));
				rChild().pointUpdate(index, value);
			}
			recalculate();
//			out.println("sum at " + left + " to " + right + " = " + this.sum); 
		}
	}
	
	public void updateLazy() {
		if(this.lazyIndex != 0) {
//			out.println("updating index lazily " + left + " " + right);
			this.left += this.lazyIndex;
			this.right += this.lazyIndex;
//			out.println("updated index lazily " + left + " " + right);
			if(left != right) {
				lChild.lazyIndex += this.lazyIndex;
				rChild.lazyIndex += this.lazyIndex;
			}
			this.lazyIndex = 0;
		}
		if(this.lazyForSwap != -1) {
			if(this.lazyForSwap == this.level - 1) {
				swap(this.level - 1);
			}
			else {
				if(left != right) {
					lChild.lazyForSwap = this.lazyForSwap;
					rChild.lazyForSwap = this.lazyForSwap;
				}
			}
			this.lazyForSwap = -1;
		}
		if(this.lazyForReverse != -1) {
			if(this.lazyForReverse == this.level) {
				swap(this.level - 1);
				if(left != right) {
					lChild.lazyForReverse = this.lazyForReverse - 1;
					rChild.lazyForReverse = this.lazyForReverse - 1;
				}
			}else {
				if(left != right) {
					lChild.lazyForReverse = this.lazyForReverse;
					rChild.lazyForReverse = this.lazyForReverse;
				}
			}
			this.lazyForReverse = -1;
		}
	}
	public void swap(int difference) {
//		out.println("In swap function");
//		difference--;
		if(left == right)return;
		lChild.lazyIndex += (1<<difference);
		rChild.lazyIndex -= (1<<difference);
		SegmentTree temp = this.lChild;
		this.lChild = this.rChild;
		this.rChild = temp;
	}
	public void reverse(int ql, int qr, int k) {
		updateLazy();
		if(qr < this.left || ql > this.right) { // NO OVERLAP
			return;
		}
		if(ql <= this.left && qr >= this.right) {
			if(this.level == k) {
				swap(k-1);
				if(left != right) {
					lChild.lazyForReverse = k - 1;
					rChild.lazyForReverse = k - 1;
				}
			}else {
				lChild.lazyForReverse = k;
				rChild.lazyForReverse = k;
			}
			this.lazyForReverse = -1;
			return;
		}
		lChild.reverse(ql, qr, k);
		rChild.reverse(ql, qr, k);
		recalculate();
	}
	public void swap(int ql, int qr, int k) {
		updateLazy();
		if(qr < this.left || ql > this.right) { // NO OVERLAP
			return;
		}
		if(ql <= this.left && qr >= this.right) {
			if(this.level - 1 == k) {
//				out.println("Swapping at left = " + left + " right = " + right);
				swap(k);
			}else {
				lChild.lazyForSwap = k;
				rChild.lazyForSwap = k;
			}
			this.lazyForSwap = -1;
			return;
		}
		lChild.swap(ql, qr, k);
		rChild.swap(ql, qr, k);
		recalculate();
	}
	public long sum(int ql, int qr) {
		if(ql <= 0 && qr >= (1<<level) - 1) { // COMPLETE OVERLAP
			return this.sum;
		}
		if(qr < 0 || ql >= (1<<level)) { // NO OVERLAP
			return 0;
		}
		long ans = lChild().sum(ql, qr) + rChild().sum(ql - (1<<(level-1)) , qr-(1<<(level-1)));
		recalculate();
		return ans;
	}
	
}
public static void main(String[] args){

   new Thread(null, null, "Anshum Gupta", 99999999) {
        public void run() {
            try {
                solve();
            } catch(Exception e) {
                e.printStackTrace();
                System.exit(1);
            }
        }
    }.start();
}
static final long mxx = (long)(1e18+5);
static final int mxN = (int)(1e6);
static final int mxV = (int)(1e6), log = 18;
static long mod = (long)(1e9+7); //998244353;//̇
static final int INF = (int)1e9;
static boolean[][]vis;
static ArrayList<ArrayList<Integer>> adj;
static int n, m, k, q, p;
static char[]str;
static int[]a;
static boolean[]flipped;
public static void solve() throws Exception {
	   // solve the problem here
		s = new MyScanner();
   		out = new PrintWriter(new BufferedOutputStream(System.out), true);
//	   		out = new PrintWriter("output.txt");
        int tc = 1;//s.nextInt();
        while(tc-- > 0){
        	n = s.nextInt();
        	q = s.nextInt();	
        	a = s.nextIntArray(1<<n);
        	flipped = new boolean[n+1];
        	SegmentTree segTree = new SegmentTree(a, 0, (1<<n)-1, n);
        	while(q-- > 0) {
        		int type = s.nextInt();
        		if(type == 1) {
        			int x = s.nextInt()-1, k = s.nextInt();
        			segTree.pointUpdate(x, k);
        		}else if(type == 2) {
        			int k = s.nextInt();
        			for(int i=0; i<=k; i++)flipped[i] ^= true;
        		}else if(type == 3) {
        			int k = s.nextInt();
        			flipped[k+1] ^= true;
        		}else {
        			int ql = s.nextInt()-1, qr = s.nextInt()-1;
        			long sum = segTree.sum(ql, qr);
//        			segTree.printTree();
        			out.println(sum);
        		}
        	}
        } 
           
        out.flush();
        out.close();
}

public static PrintWriter out;
public static MyScanner s;
static class MyScanner {

    BufferedReader br;
    StringTokenizer st;

    public MyScanner() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }
    public MyScanner(String fileName) {
    	try {
			br = new BufferedReader(new FileReader(fileName));
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		}
    }
    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() { return Integer.parseInt(next()); }
    long nextLong() { return Long.parseLong(next()); }
    double nextDouble() { return Double.parseDouble(next()); }
    int[] nextIntArray(int n){
    	int[]a = new int[n];
    	for(int i=0; i<n; i++) {
    		a[i] = this.nextInt();
    	}
    	return a;
    }
    long[] nextlongArray(int n) {
    	long[]a = new long[n];
    	for(int i=0; i<n; i++) {
    		a[i] = this.nextLong();
    	}
    	return a;
    }
    Integer[] nextIntegerArray(int n){
    	Integer[]a = new Integer[n];
    	for(int i=0; i<n; i++) {
    		a[i] = this.nextInt();
    	}
    	return a;
    }
    Long[] nextLongArray(int n) {
    	Long[]a = new Long[n];
    	for(int i=0; i<n; i++) {
    		a[i] = this.nextLong();
    	}
    	return a;
    }
    char[][] next2DCharArray(int n, int m){
    	char[][]arr = new char[n][m];
    	for(int i=0; i<n; i++) {
    		arr[i] = this.next().toCharArray();
    	}
    	return arr;
    }
    ArrayList<ArrayList<Integer>> readUndirectedUnweightedGraph(int n, int m) {
    	ArrayList<ArrayList<Integer>>adj = new ArrayList<ArrayList<Integer>>();
    	for(int i=0; i<=n; i++)adj.add(new ArrayList<Integer>());
    	for(int i=0; i<m; i++) {
    		int u = s.nextInt();
    		int v = s.nextInt();
    		adj.get(u).add(v);
    		adj.get(v).add(u);
    	}
    	return adj;
    }
    ArrayList<ArrayList<Integer>> readDirectedUnweightedGraph(int n, int m) {
    	ArrayList<ArrayList<Integer>>adj = new ArrayList<ArrayList<Integer>>();
    	for(int i=0; i<=n; i++)adj.add(new ArrayList<Integer>());
    	for(int i=0; i<m; i++) {
    		int u = s.nextInt();
    		int v = s.nextInt();
    		adj.get(u).add(v);
    	}
    	return adj;
    }
    String nextLine(){
        String str = "";
        try {
            str = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return str;
    }
}

 
}
