Tree Visits

Maintain a value X under increments of 2^C modulo 2^N, mark all nodes on each root-to-leaf walk, and report the count of distinct visited nodes.

Medium7TreeBit manipulationPrefix sumImplementationNo attempts yetTime limit5sMemory limit1536 MB

Problem

There is a perfect binary tree of height NN. It has 2N+112^{N+1}-1 nodes in total, and 2N2^N of them are leaves at depth NN.

You walk down the tree using an NN-bit binary number XX. Read the bits of XX starting from the leftmost one: a 0 takes you to the left child, a 1 takes you to the right child. For example, when N=2N = 2, X=0=002X = 0 = 00_2 takes you to the leftmost leaf, and X=3=112X = 3 = 11_2 takes you to the rightmost leaf. With X=2=102X = 2 = 10_2 you move from the root to its right child, then to that child's left child.

At the very beginning X=0X = 0 and only the root has been visited. Write a program that processes the following two queries.

  • 1 C: change XX to (X+2C)mod2N(X + 2^C) \bmod 2^N. Then walk down from the root using the new XX and visit every node you pass. The root and the leaf you land on both count as visited nodes.
  • 2: print how many distinct nodes have been visited so far. A node visited several times is counted once.

Input

The first line contains the height NN of the tree and the number of queries QQ. (1N,Q1051 \le N, Q \le 10^5)

Each of the next QQ lines contains one query. A query of the first kind has the form 1 C with 0C<N0 \le C < N. A query of the second kind is the single character 2, and at least one such query is given.

Output

For each query of the second kind, print the number of distinct visited nodes on its own line.