Matrix Multiplication

Interview

Time limit1sMemory limit128 MB

Summary
Read two matrices of bounded size and print their standard matrix product.
Level

Easy2 of 10

Topics
Matrix, Implementation
Solved
No attempts yet

Problem

Given an N x M matrix A and an M x K matrix B, write a program that computes the product A x B.

Input

The first line contains the size of matrix A, N and M. The next N lines contain the entries of matrix A, with M integers per row. The following line contains the size of matrix B, M and K. The next M lines contain the entries of matrix B, with K integers per row.

N, M, and K are at most 100, and every matrix entry is an integer whose absolute value is at most 100.

Output

Print the product matrix A x B in N lines. In each line, print K entries separated by spaces.

Examples1

  1. Example 1

    Input
    3 2
    1 2
    3 4
    5 6
    2 3
    -1 -2 0
    0 0 3
    
    Expected output
    -1 -2 6
    -3 -6 12
    -5 -10 18