402840: GYM100917 G Game ``Minesweeper''

Memory Limit:256 MB Time Limit:1 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

G. Game "Minesweeper"time limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard output

This is interactive problem.

Rules of the Minesweeper game are simple: given a grid 16 × 16. Each cell in the grid either is empty or contains a mine. Goal of the game is to label all mines with the flags and open all empty cells. If player opens empty cell, it contains one integer — number of mines in neighbor cells. Two cells are neighbors, if their borders have at least one common point (so each internal cell have 8 neighbors). If a cell, containing an integer 0 is opened (by player or automatically), all neighbors of this cell are opened automatically.

Player can do the following operations:

  1. Single click on unopened cell to open this cell. If this cell contains the mine, game is lost. Otherwise cell is opened.
  2. Double click on the opened cell which contains an non-zero integer. If number of labels in the neighbor cells is equal to this integer, all non-labeled neighbors are opened. If labeing was wrong, game is lost.
  3. Toggle a label on the unopened cell. If cell was not labeled, it is labeled as containing the mine. If cell was labeled, label is removed.
  4. Finish the game.

If after the end of game all empty cells are opened and all cells with mines are labeled, player wins, otherwise game is lost.

You are given coordinates of cell, which does not contain a mine. Moreover, it's guaranteed that it's possible to win the game without any nondeterministic situation (where guessing is needed). Your goal is to win.

Input

At the beginning of interaction your program must read two integers — row r and column c of the safe cell (1 ≤ r, c ≤ 16).

Then on each your request you receive next information:

First line of the answer contains one integer N — number of cells with changed status. Each of next N lines contain two integers ri and ci — row and column of the cell, and si — status of the cell: digit between 0 and 8, if the cell is empty, '*', if the cell was labeled or '-', if label from cell was removed.

Output

If you want to finish the game, print ("4") and end of the line. Otherwise print three space-separated integers: type of operation, row and column (1-based) of the cell to which it is applied. Do not forget to add end of the line character and flush the output buffer.

ExampleInput
1 1
 
6
1 1 0
1 2 0
2 1 1
2 3 1
1 3 0
2 2 2
 
1
3 2 *
 
1
3 2 -
 
1
3 1 *
 
1
3 2 2
 
1
3 3 *
Output
 
1 1 1
 
 
 
 
 
 
 
3 3 2
 
 
3 3 2
 
 
3 3 1
 
 
2 2 1
 
 
3 3 3
 
 
4
Note

Sample in the statement contains example of the interaction protocol for board 3 × 3.

加入题单

算法标签: