Under construction

Still being built. Things may change

Farmer John's Cheese Block

Interview

Time limit2sMemory limit2048 MB

Summary
After each removal of a unit cube from an N x N x N block, count the 1 x 1 x N bricks that still fit in the remaining cheese.
Level

Medium4 of 10

Topics
Array, Implementation
Solved
No attempts yet

Problem

Farmer John has a block of cheese in the shape of a cube. It lies on the 3-dimensional coordinate plane, extending from (0,0,0)(0,0,0) to (N,N,N)(N, N, N) (2≤N≤10002 \leq N \leq 1000). Farmer John will perform a series of QQ (1≤Q≤2⋅1051 \leq Q \leq 2 \cdot 10^5) update operations to his cheese block.

For each update operation, FJ carves out the 1×1×11 \times 1 \times 1 block of cheese extending from integer coordinates (x,y,z)(x, y, z) to (x+1,y+1,z+1)(x+1, y+1, z+1), where 0≤x,y,z<N0 \leq x, y, z < N. It is guaranteed that a 1×1×11 \times 1 \times 1 block of cheese exists at the location FJ carves. Since FJ is playing Moocraft, gravity does not cause parts of the cheese to fall if the cheese below is carved.

After each update, output the number of distinct configurations in which FJ can stick a 1×1×N1 \times 1 \times N brick into the cheese block such that no part of the brick overlaps any remaining cheese. Every vertex of the brick must have integer coordinates in the range [0,N][0, N] on all three axes. FJ may rotate the brick however he wants.

Input

The first line contains NN and QQ.

Each of the following QQ lines contains xx, yy, and zz, the coordinates to carve.

Output

After each update, output one integer: the number of configurations.

Hint

After the first three updates, the 1×2×11 \times 2 \times 1 brick spanning [0,1]×[0,2]×[0,1][0, 1] \times [0, 2] \times [0, 1] does not overlap the remaining cheese, so it contributes to the answer.

Examples1

  1. Example 1

    Input
    2 5
    0 0 0
    1 1 1
    0 1 0
    1 0 0
    1 1 0
    
    Expected output
    0
    0
    1
    2
    5