#C7085. Matrix Multiplication Challenge

    ID: 50917 Type: Default 1000ms 256MiB

Matrix Multiplication Challenge

Matrix Multiplication Challenge

You are given two matrices \(A\) and \(B\). Your task is to compute their product \(C = A \times B\), if the matrices are conformable for multiplication. Recall that two matrices can be multiplied if and only if the number of columns in \(A\) equals the number of rows in \(B\), i.e., if \(A\) is of dimensions \(n \times m\) and \(B\) is of dimensions \(m \times p\), then the result will be a matrix \(C\) with dimensions \(n \times p\).

If the matrices are not conformable, output an empty matrix represented by [].

Input/Output Specification:

The input is read from stdin and the output must be printed to stdout.

inputFormat

The input consists of two matrices provided in the following format:

  1. The first line contains two integers \(n\) and \(m\), representing the number of rows and columns of the first matrix \(A\).
  2. The next \(n\) lines each contain \(m\) space-separated integers, representing the rows of matrix \(A\).
  3. The following line contains two integers \(p\) and \(q\), representing the number of rows and columns of the second matrix \(B\).
  4. The next \(p\) lines each contain \(q\) space-separated integers, representing the rows of matrix \(B\).

Note: If either matrix is empty (i.e. \(n=0\) or \(p=0\)), treat it as an invalid matrix for multiplication.

outputFormat

If matrix multiplication is possible, output the resulting matrix \(C\) in which each row is printed on a new line with the elements separated by a single space. If the multiplication is not possible, output a single line containing [].

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

139 154

</p>