Welcome to ZOJ
Information
Select Problem
Runs
Ranklist
ZOJ Problem Set - 2363
Strange Counter

Time Limit: 5 Seconds      Memory Limit: 32768 KB      Special Judge

The new secret counter invented in one theoretical computer science lab is the great breakthrough in the computer microschemes design. This counter consists of N registers numbered from 0 to N - 1, each of which contains 0, 1 or 2. If the number in the i-th register is Ai, the number stored in the counter is

One can see that the same number can be stored in the counter in several different ways. For example, the number 5 can be stored in a 3-register counter as (1, 0, 1) or as (0, 2, 1).

The main feature of the counter is that it can add numbers that are powers of two to the number stored in the counter, only changing the value of a small number of registers. Namely, the scientists of the lab developed the scheme that allowed adding such number changing no more than four registers!

Unfortunately after the recent experiments in the neighbouring physics lab, involving the creation of the artificial black hole, the theoretical computer science laboratory was accidently destroyed. However, the supercomputer project that the counter was designed for is still on, so you were asked to reinvent the counter.


This problem contains multiple test cases!

The first line of a multiple input is an integer N, then a blank line followed by N input blocks. Each input block is in the format indicated in the problem description. There is a blank line between input blocks.

The output format consists of N output blocks. There is a blank line between output blocks.


Input

The first line of the input file contains N - the number of registers in the counter (1 <= N <= 1 000). Initially all registers contain zeroes. The second line contains M - the number of additions you have to make (1 <= M <= 10 000). The third line contains M integer numbers ranging from 0 to N - 1. Number i means that you must add 2i to the number in the counter. There sum of all numbers added to the register does not exceed 2N - 1.


Output

Output file must contain M lines. Each line must contain the changes made adding the corresponding number to the counter.

The first number in each line must be K - the number of registers changed (1 <= K <= 4). K pairs must follow - for each changed register first output its number and then the new value.


Sample Input

1

5
6
0 0 0 1 0 0


Sample Output

1 0 1
1 0 2
2 0 1 1 1
1 1 2
1 0 2
3 0 1 1 1 2 1



Author: Andrew Stankevich
Source: Andrew Stankevich's Contest #3
Submit    Status