#C3583. Grid Word Placement

    ID: 47026 Type: Default 1000ms 256MiB

Grid Word Placement

Grid Word Placement

You are given an integer n which represents the size of a square grid. The grid is initially filled with space characters. You need to support two operations:

  • H row col word: Place the word horizontally in the grid starting at the specified row and col index.
  • V row col word: Place the word vertically in the grid starting at the specified row and col index.

The grid uses 0-indexing. An operation D indicates that you should display (print) the current state of the grid. The display of the grid is done by concatenating each row into a string and separating rows with newline characters.

If a word cannot be placed because it extends beyond the grid boundaries, an IndexError (or the equivalent error in your language) should be raised. In this problem, however, you may assume all placement operations are valid.

The following condition must always hold for a placement operation:

\[ col + \text{len(word)} \leq n \quad \text{for horizontal placement}, \]

and

\[ row + \text{len(word)} \leq n \quad \text{for vertical placement}. \]

inputFormat

The first line contains an integer n, the size of the grid.

The second line contains an integer m, the number of operations.

The following m lines each contain an operation in one of the following formats:

  • H row col word — Place the word horizontally.
  • V row col word — Place the word vertically.
  • D — Display the current grid (this will appear as the final operation in each test case).

All input is read from standard input (stdin).

outputFormat

Output the grid as n lines, where each line is a concatenation of characters (without spaces separating them) representing a row of the grid. The output should be printed to standard output (stdout).

## sample
3
1
D