#K46842. Minimal Commands to Feed the Animals

    ID: 28066 Type: Default 1000ms 256MiB

Minimal Commands to Feed the Animals

Minimal Commands to Feed the Animals

You are given an m × n grid which contains several cages. Each cage is located at a specified cell given by its row and column coordinates. Your task is to generate a minimal set of commands to feed the animals in these cages.

For each cage, you must produce two commands:

  • One command to feed by the row number.
  • One command to feed by the column number.

The commands for a cage located at \( (r, c) \) should be output in the following order:
First, a command that outputs 1 r, then a command that outputs 1 c.

The first line of the output should be the number of cages.

Note: Input is read from standard input and output is written to standard output.

inputFormat

The input is given via standard input in the following format:

  m n c
  r1 c1
  r2 c2
  ...
  rc cc

Here:

  • \( m \) is the number of rows in the grid.
  • \( n \) is the number of columns in the grid.
  • \( c \) is the number of cages.
  • Each of the next \( c \) lines contains two integers \( r \) and \( c \), representing the row and column of a cage.

outputFormat

The output, written to standard output, should be formatted as follows:

  k
  command1
  command2
  ...

Where:

  • \( k \) is the number of cages (note that each cage yields two commands, but \( k \) remains the count of cages).
  • For each cage (in the same order as input), two lines are printed:
    • The first line is: 1 r (feeding by row).
    • The second line is: 1 c (feeding by column).
## sample
3 3 3
1 1
2 2
3 3
3

1 1 1 1 1 2 1 2 1 3 1 3

</p>