Under construction

Still being built. Things may change

Collecting Images is Fun

Time limit5sMemory limit256 MB

Summary
Start with an all-white 2^N by 2^N grid; after each of Q row or column flips, report the size of the quadtree that represents the image.
Level

Hard8 of 10

Topics
Divide and conquer, Implementation, Math, Bit manipulation
Solved
No attempts yet

Problem

JOI loves collecting images and has a lot of them. Recently he noticed that he has collected too many images and his hard disk is running low on space. He does not have the money to buy a new hard disk, and deleting the images he owns would pain him more than anything, so he decided to compress the images well and reduce the space they take.

An image is represented by 2N×2N2^N \times 2^N pixels arranged in a square with 2N2^N rows and 2N2^N columns. Each pixel is either white or black.

JOI decided to compress such an image in the following way.

  • If all pixels in the image have the same color, record only that color. The size of the compressed data is then 1.
  • Otherwise, split the image into 4 smaller images. If the image has 2k2^k rows and 2k2^k columns, split it at the center both vertically and horizontally to obtain 4 images with 2k−12^{k-1} rows and 2k−12^{k-1} columns. Compress these 4 smaller images in the same way. The size of the compressed data is then the sum of the sizes of the compressed data of the 4 smaller images, plus 1.

JOI became worried about whether this method really compresses images, so he decided to experiment with various images. The experiment works as follows.

  • First, prepare an image in which every pixel is white.
  • For i=1,…,Qi = 1, \dots, Q, perform the operation: "if Ti=0T_i = 0, invert the colors of the 2N2^N pixels in the XiX_i-th row counted from the top; if Ti=1T_i = 1, invert the colors of the 2N2^N pixels in the XiX_i-th column counted from the left." That is, writing the pixel in row aa from the top and column bb from the left as (a,b)(a, b), for each ii: if Ti=0T_i = 0, then for every pixel (Xi,b)(X_i, b) with 1≤b≤2N1 \le b \le 2^N, and if Ti=1T_i = 1, then for every pixel (a,Xi)(a, X_i) with 1≤a≤2N1 \le a \le 2^N, change white pixels to black and black pixels to white.
  • For each ii, find the size of the compressed data when the image after the ii-th operation is compressed by JOI's method.

To perform as many operations as possible in the experiment, the size of the compressed data must be found quickly.

Given the integer NN representing the image size, the number of operations QQ, and the instructions for the QQ operations, write a program that finds the size of the compressed data when the image after each operation is compressed by JOI's method.

Input

Read the following input from standard input.

  • The first line contains two integers N,QN, Q separated by a space, representing that the image has 2N2^N rows and 2N2^N columns and that QQ operations are performed.
  • The following QQ lines contain the operation instructions. The ii-th of these QQ lines (1≤i≤Q1 \le i \le Q) contains two integers Ti,XiT_i, X_i (0≤Ti≤10 \le T_i \le 1 and 1≤Xi≤2N1 \le X_i \le 2^N) separated by a space, representing that the ii-th operation inverts the colors of all pixels in the XiX_i-th row from the top if Ti=0T_i = 0, or in the XiX_i-th column from the left if Ti=1T_i = 1.

Output

Output QQ lines to standard output. The ii-th line (1≤i≤Q1 \le i \le Q) contains a single integer: the size of the compressed data when the image after the ii-th operation is compressed by JOI's method.

Constraints

  • 1≤N≤201 \le N \le 20.
  • 1≤Q≤2 000 0001 \le Q \le 2\,000\,000.

Examples1

  1. Example 1

    Input
    2 3
    0 1
    1 2
    0 3
    
    Expected output
    13
    17
    21