#C6901. Flower Garden Rearrangement

    ID: 50713 Type: Default 1000ms 256MiB

Flower Garden Rearrangement

Flower Garden Rearrangement

You are given a garden represented as an n x m grid, where each cell contains an integer representing a type of flower. You are allowed to rearrange (i.e. swap) the flowers arbitrarily. The goal is to determine whether it is possible to rearrange the flowers so that each row contains exactly k distinct types of flowers.

Note:

  • If k > m, it is impossible since a row cannot have more distinct flower types than the number of its cells.
  • Also, if the total number of distinct flower types in the entire garden is less than k, it is impossible to satisfy the condition in every row.

Formally, you have to decide if the following conditions can be satisfied after an arbitrary rearrangement:

\( k \le m \quad \text{and} \quad \text{Total number of distinct flowers in the garden} \ge k \).

If both conditions are met, output possible; otherwise, output impossible.

inputFormat

The input is read from standard input and has the following format:

n m k
row_1 (m integers separated by spaces)
row_2 (m integers separated by spaces)
... 
row_n (m integers separated by spaces)

Here, n is the number of rows, m is the number of columns, and k is the required number of distinct flower types in every row after rearrangement.

outputFormat

Output a single line to standard output containing either possible or impossible depending on whether it is possible to rearrange the flowers to satisfy the condition.

## sample
3 4 3
1 2 3 4
5 6 7 8
9 10 11 12
possible