#P2049. 魔术棋子

魔术棋子

Description

In an M×NM \times N magic chessboard, each cell contains an integer. When a chess piece steps into a cell, the number on the piece is multiplied by the number in that cell. A chess piece moves from the top-left corner to the bottom-right corner, and it can only move right or down. After it reaches the bottom-right corner, what values modulo KK can the number on the piece be?

For the following 2×32 \times 3 board:

3    4    4
5    6    6

The piece starts with the number 11, enters the board from the top-left, and moves to the bottom-right. In the example above, the final number on the piece can be 288,432288, 432, or 540540. Therefore, when K=5K = 5, the final possible results are: 0,2,30, 2, 3.

Input Format

The first line contains three integers, M,N,K(1M,N,K100)M,N,K (1 \leq M,N,K \leq 100). The next MM lines each contain NN integers, representing the numbers in the matrix.

Output Format

The first line contains the count of possible results.

The second line contains all possible results in ascending order.

2 3 5
3 4 4
5 6 6

3
0 2 3

Hint

Translated by ChatGPT 5