#C353. Matrix Multiplication

    ID: 46967 Type: Default 1000ms 256MiB

Matrix Multiplication

Matrix Multiplication

You are given two matrices. Your task is to compute their product provided that the number of columns in the first matrix is equal to the number of rows in the second matrix. The product matrix \(C\) is defined as follows:

\(C[i][j] = \sum_{k=0}^{m-1} A[i][k] \times B[k][j]\)

If the multiplication is not possible, output None.

inputFormat

The input is read from standard input (stdin) and follows this format:

  • The first line contains two integers \(n_1\) and \(m_1\) representing the number of rows and columns in the first matrix.
  • The next \(n_1\) lines each contain \(m_1\) integers separated by spaces, representing the first matrix.
  • Then, a line with two integers \(n_2\) and \(m_2\) representing the number of rows and columns in the second matrix.
  • The next \(n_2\) lines each contain \(m_2\) integers separated by spaces, representing the second matrix.

It is guaranteed that all numbers are integers.

outputFormat

If matrix multiplication is possible (i.e. (m_1 = n_2)), output the resulting matrix row by row. Each row should be printed as a sequence of space-separated integers on a new line. If multiplication is not possible, output exactly the string None.## sample

2 2
1 2
3 4
2 2
5 6
7 8
19 22

43 50

</p>