Problem:


  MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});

Matrix Multiplication

Write a program which reads a $n \times m$ matrix $A$ and a $m \times l$ matrix $B$, and prints their product, a $n \times l$ matrix $C$. An element of matrix $C$ is obtained by the following formula:

\[
c_{ij} = \sum_{k=1}^m a_{ik}b_{kj}
\]

  where $a_{ij}$, $b_{ij}$ and $c_{ij}$ are elements of $A$, $B$ and $C$ respectively.

Input

  In the first line, three integers $n$, $m$ and $l$ are given separated by space characters

  In the following lines, the $n \times m$ matrix $A$ and the $m \times l$ matrix $B$ are given.

Output

  Print elements of the $n \times l$ matrix $C$ ($c_{ij}$). Print a single space character between adjacent elements.

Constraints

$1 \leq n, m, l \leq 100$

$0 \leq a_{ij}, b_{ij} \leq 10000$

Sample Input

3 2 3
1 2
0 3
4 5
1 2 1
0 3 2

Sample Output

1 8 5
0 9 6
4 23 14

Note

      解説      

	



Sample input:
3 2 3
1 2
0 3
4 5
1 2 1
0 3 2


Sample output:
1 8 5
0 9 6
4 23 14

Submission status: Accepted

Solution code:
# coding: utf-8
def main():
    n, m, l = map(int, raw_input().split())
    mat_A = [] # (n, m)
    mat_B = [] # (m, l)
    for i in range(n):
        mat_A.append(map(int, raw_input().split()))

    for j in range(m):
        mat_B.append(map(int, raw_input().split()))

    for i in range(n):
        c = [0 for g in range(l)]
        for j in range(l):
            for k in range(m):
              #  print "n:{}, m:{}, l:{}".format(i,k,j)
                try:
                    c[j] += mat_A[i][k] * mat_B[k][j]
                except:
                    print "n: {}, m: {}, l: {}".format(i,k,j)
        print " ".join(map(str, c))
if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
n, m, l = map(int, input().split())
a = [[v for v in list(map(int, input().split()))] for i in range(n)]
b = [[v for v in list(map(int, input().split()))] for i in range(m)]
c = [[sum([a[j][x] * b[x][i] for x in range(m)]) for i in range(l)] for j in range(n)]
for i in range(n):
    print(' '.join(map(str, c[i])))

Submission status: Accepted

Solution code:
import sys

array_data = map(int, raw_input().split())
n = array_data[0]
m = array_data[1]
l = array_data[2]

a = []
for i in range(n):
	partial_a = map(int, raw_input().split())
	a.append(partial_a)

b = []
for j in range(m):
	partial_b = map(int, raw_input().split())
	b.append(partial_b)

c = []
for i in range(n):
	c.append([])
	for j in range(l):
		c[i].append([])
		wa = 0
		for k in range(m):
			wa += a[i][k] * b[k][j]
		c[i][j] = wa

for i in range(len(c)):
	for j in range(len(c[i])):
		if j != len(c[i])-1:
			sys.stdout.write("{:} ".format(c[i][j]))
		else:
			print(c[i][j])

Submission status: Accepted

Solution code:
def main():

    n, m, l = map(int, input().split())
    matrix_a = [list(map(int, input().split())) for i in range(n)]
    matrix_b = [list(map(int, input().split())) for j in range(m)]
    matrix_c = [[0 for i in range(l)] for j in range(n)]
    for i in range(n):
        for j in range(l):
            matrix_c[i][j] = sum(matrix_a[i][k] * matrix_b[k][j] for k in range(m))

    for row in matrix_c:
        print(' '.join(map(str, row)))

main()

Submission status: Accepted

Solution code:
def matprod(A,B):
    C = []
    for i in range(len(A)):
        tmpList = []
        for k in range(len(B[0])):
            tmpVal = 0
            for j in range(len(A[0])):
                tmpVal += A[i][j] * B[j][k]
            tmpList.append(tmpVal)
        C.append(tmpList)
    return C


n,m,l = map(int, input().split())

A = []
for i in range(n):
    A.append(list(map(int, input().split())))

B = []
for i in range(m):
    B.append(list(map(int, input().split())))


for cr in matprod(A,B):
    print(' '.join(map(str, cr)))

Submission status: Accepted

Solution code:
n, m, l = [int(s) for s in input().split()]
A = []
B = []
C = [[0 for i in range(l)] for i in range(n)]

for i in range(n):
    A.append([int(s) for s in input().split()])
for i in range(m):
    B.append([int(s) for s in input().split()])

for i,row in enumerate(C):
    for j in range(len(row)):
        for k in range(m):
            C[i][j] += A[i][k] * B[k][j]


for row in C:
    print(' '.join([str(i) for i in row]))

Submission status: Accepted

Solution code:
# Belongs to : midandfeed aka asilentvoice
n, m, l = [int(x) for x in input().split()]
a = [[int(x) for x in input().split()] for i in range(n)]
b = [[int(x) for x in input().split()] for i in range(m)]
ans = []

for i in range(n):
	rtemp = []
	for j in range(l):
		temp = 0
		for k in range(m):
			temp += (a[i][k] * b[k][j])
		rtemp.append(temp)
	ans.append(rtemp)
	
for row in ans:
	print(" ".join(map(str, row)))

Submission status: Accepted

Solution code:
# -*-coding:utf-8

def main():

    n, m, l = map(int, input().split())
    A = []
    B = []

    for i in range(n):
        A.append(list(map(int, input().split())))

    for i in range(m):
        B.append(list(map(int, input().split())))

    Ans = []
    for i in range(n):
        row = []
        for j in range(l):
            rowSum = 0
            for k in range(m):
                rowSum += A[i][k] * B[k][j]
            row.append(rowSum)

        Ans.append(row)

    for i in range(n):
        print(' '.join([str(a) for a in Ans[i]]))

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
s=input().split()
n=int(s[0]);m=int(s[1]);l=int(s[2])
a=[[0 for j in range(m)]for i in range(n)]
b=[[0 for j in range(l)]for i in range(m)]
c=[[0 for j in range(l)]for i in range(n)]
for i in range(n):
    t=input().split()
    for j in range(m):
        a[i][j]=int(t[j])
for i in range(m):
    t=input().split()
    for j in range(l):
        b[i][j]=int(t[j])
for i in range(n):
    for j in range(l):
        for k in range(m):
            c[i][j]+=a[i][k]*b[k][j]
        sys.stdout.write("{0}".format(c[i][j]))
        if j==l-1:
            sys.stdout.write("\n")
        else:
            sys.stdout.write(" ")

Submission status: Accepted

Solution code:
def main():
    n, m, l = map(int, input().split())

    nm_mat = [
        [int(x) for x in input().split()]
        for _ in range(n)
    ]
    ml_mat = [
        [int(x) for x in input().split()]
        for _ in range(m)
    ]
    nl_mat = [
        [0] * l
        for _ in range(n)
    ]

    for i_n, row in enumerate(nm_mat):
        for i_l in range(l):
            col = [ml_mat[i_m][i_l] for i_m in range(m)]
            inner_product = sum(x * y for x, y in zip(row, col))

            nl_mat[i_n][i_l] = inner_product

    for row in nl_mat:
        print(" ".join(map(str, row)))

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
n,m,l=map(int,input().split())
a=[[int(_) for _ in input().split()] for i in range(n)]
b=[[int(_) for _ in input().split()] for i in range(m)]
c=[[0]*l for _ in range(n)]
for i in range(n):
 for j in range(l):
  for k in range(m):
   c[i][j]+=a[i][k]*b[k][j]
for i in range(n):
 print(*c[i])

Submission status: Accepted

Solution code:
n,m,l=map(int,input().split())
a=[list(map(int,input().split())) for _ in range(n)]
b=[list(map(int,input().split())) for _ in range(m)]
[print(*x)for x in[[sum(s*t for s,t in zip(c,l))for l in zip(*b)]for c in a]]

Submission status: Accepted

Solution code:
n,m,l=map(int,input().split())
a=[list(map(int,input().split()))for _ in range(n)]
b=[list(map(int,input().split()))for _ in range(m)]
[print(*x)for x in[[sum([s*t for s,t in zip(c,l)])for l in zip(*b)]for c in a]]

Submission status: Accepted

Solution code:
# 00.11 sec    7004 KB    5 lines     214 bytes 
n,m,l=map(int,input().split())
a=[list(map(int,input().split()))for _ in range(n)]
b=[list(map(int,input().split()))for _ in range(m)]
[print(*x)for x in[[sum(s*t for s,t in zip(c,l))for l in zip(*b)]for c in a]]

Submission status: Accepted

Solution code:
n,m,l=map(int,input().split())
a=[list(map(int,input().split()))for _ in range(n)]
b=[list(map(int,input().split()))for _ in range(m)]
[print(*x)for x in[[sum(s*t for s,t in zip(c,l))for l in zip(*b)]for c in a]]

Submission status: Accepted

Solution code:
n, m, l = map(int, input().split())
a = [list(map(int, input().split())) for i in range(n)]
b = [list(map(int, input().split())) for i in range(m)]

for i in a:
    result = []
    for j in zip(*b):
        result.append(sum([a * b for (a,b) in zip(i, j)]))
    print(*result)

Submission status: Accepted

Solution code:
n,m,l=map(int,input().split())
matrix_a=[]
matrix_b=[]
matrix_c=[]
for i in range(n):
    matrix_a.append(list(map(int,input().split())))
for i in range(m):
    matrix_b.append(list(map(int,input().split())))
tmp_l=list()
for i in range(n):
    for j in range(l):
        tmp_n=0
        for k in range(m):
            tmp_n+=matrix_a[i][k]*matrix_b[k][j]
        tmp_l.append(tmp_n)
    matrix_c.append(tmp_l.copy())
    tmp_l.clear()
for i in matrix_c:
    tmp=0
    for j in i:
        tmp+=1
        if tmp==l:
            print(j,end="")
        else:
            print(j,"",end="")
    print()

Submission status: Accepted

Solution code:
n,m,l=map(int, input().split())
a=[list(map(int, input().split())) for i in range(n)]
b=[list(map(int, input().split())) for i in range(m)]
for i in a:
    result = []
    for j in zip(*b):
        result.append(sum([a * b for (a,b) in zip(i, j)]))
    print(*result)

Submission status: Accepted

Solution code:
n, m, l = map(int, raw_input().split())
a = []
for _ in range(n):
	a.append(map(int, raw_input().split()))
b = []
for _ in range(m):
	b.append(map(int, raw_input().split()))

c = [[0 for j in range(l)] for i in range(n)]
for i in range(n):
	for j in range(l):
		for k in range(m):
			c[i][j] += a[i][k]*b[k][j]
	print ' '.join(map(str, c[i]))

Submission status: Accepted

Solution code:
n, m, ll = map(int, input().split())

a = []
b = []

for i in range(n):
    a.append(list(map(int, input().split())))
for i in range(m):
    b.append(list(map(int, input().split())))

for i in range(n):
    prt = []
    for j in range(ll):
        s = 0
        for k in range(m):
            s += a[i][k] * b[k][j]
        prt.append(s)
    print(*prt)

Submission status: Accepted

Solution code:
n, m, l = map(int, input().split())
A = [tuple(map(int, input().split())) for _ in range(n)]
B = [tuple(map(int, input().split())) for _ in range(m)]
C = [[0] * l for _ in range(n)]
for i in range(n):
    for k in range(m):
        for j in range(l):
            C[i][j] += A[i][k] * B[k][j]
for i in range(n):
    print(*C[i])

Submission status: Accepted

Solution code:
# coding:utf-8
n,m,l = map(int, raw_input().split())
a = [[0 for i in range(m)] for j in range(n)]
b = [[0 for i in range(l)] for j in range(m)]
c = [[0 for i in range(l)] for j in range(n)]
for i in range(n):
    a[i] = map(int, raw_input().split())
for i in range(m):
    b[i] = map(int, raw_input().split())
for i in range(len(a)):
    for j in range(len(b[0])):
        for k in range(len(b)):
            c[i][j] += a[i][k] * b[k][j]
        else:
            print c[i][j],
    else:
        print

Submission status: Accepted

Solution code:
n,m,l = map(int,input().split())

A = [list(map(int,input().split())) for i in range(n)]
B = [list(map(int,input().split())) for i in range(m)]
C = [[0 for i in range(l)] for j in range(n)]

for i in range(n):
    for j in range(l):
        for k in range(m):
            C[i][j] += A[i][k] * B[k][j]

for i in range(n):
    print(" ".join(map(str,C[i])))

Submission status: Accepted

Solution code:
n,m,l=map(int,input().split())
a=[list(map(int,input().split()))for _ in range(n)]
b=[list(map(int,input().split()))for _ in range(m)]
for x in[[sum([s*t for s,t in zip(c,l)])for l in zip(*b)]for c in a]:print(*x)

Submission status: Accepted

Solution code:
n, m, l = map(int, input().split())

matrix_A = [list(map(int, input().split())) for _ in range(n)]
matrix_B = [list(map(int, input().split())) for _ in range(m)]

matrix_B_transposed  = list(map(list, zip(*matrix_B)))

for a in matrix_A:
    c = []
    for bt in matrix_B_transposed:
        c.append(sum(x * y for (x, y) in zip(a, bt)))
    print(*c)

Submission status: Accepted

Solution code:
# coding: UTF-8
n,m,l = map(int,raw_input().split(" "))
a_matrix = [map(int,raw_input().split()) for i in range(n)]
b_matrix = [map(int,raw_input().split()) for i in range(m)]
tmp3_matrix = []

c_matrix = []
for i in range(n):
    tmp2_matrix = []
    for j in range(l):
        sum = 0
        for k in range(m):
            sum += a_matrix[i][k] * b_matrix[k][j]
        tmp2_matrix.append(sum)
    tmp3_matrix.extend([tmp2_matrix])
c_matrix.extend(tmp3_matrix)
for x in range(n):
    print " ".join(map(str,c_matrix[x]))

Submission status: Accepted

Solution code:
n,m,l = map(int,input().split())
A = [[int(i) for i in input().split()] for _ in range(n)]
B = [[int(i) for i in input().split()] for _ in range(m)]

res = [
    [sum([
        a*b for a,b in zip(A[i],list(zip(*B))[j])
    ])
    for j in range(l)]
for i in range(n)]

for r in res:
    print(*r)

Submission status: Accepted

Solution code:
n,m,l=map(int,input().split())
a=[list(map(int,input().split()))for _ in[0]*n]
b=[list(map(int,input().split()))for _ in[0]*m]
for x in[[sum([s*t for s,t in zip(c,l)])for l in zip(*b)]for c in a]:print(*x)

Submission status: Accepted

Solution code:
x, y, z = map(int, input().split())
matrix1 = list()
matrix2 = list()
ans = list()
for i in range(x):
    matrix1.append(list(map(int, input().split())))
for j in range(y):
    matrix2.append(list(map(int, input().split())))
for i in range(x):
    row = list()
    for j in range(z):
        term = 0
        for k in range(y):
            term += matrix1[i][k]*matrix2[k][j] 
        row.append(term)
    ans.append(row)
for i in range(x):
    print (' '.join(map(str, ans[i])))

Submission status: Accepted

Solution code:
data = list(map(int, input().split()))
mat1 = [[0 for j in range(data[1])] for i in range(data[0])]
mat2 = [[0 for j in range(data[2])] for i in range(data[1])]
mat3 = [[0 for j in range(data[2])] for i in range(data[0])]
for i in range(data[0]):
    row = list(map(int, input().split()))
    for j in range(data[1]):
        mat1[i][j] = row[j]
for i in range(data[1]):
    row = list(map(int, input().split()))
    for j in range(data[2]):
        mat2[i][j] = row[j]
for i in range(data[0]):
    for j in range(data[2]):
        elem = 0
        for k in range(data[1]):
            elem += mat1[i][k] * mat2[k][j]
        mat3[i][j] = elem
for i in range(len(mat3)):
    str_mat3 = list(map(str, mat3[i]))
    print(" ".join(str_mat3))

Submission status: Accepted

Solution code:
n,m,l = [int(x) for x in input().split( )]
zeros1 = [[0 for x in range(m)] for y in range(n)]
zeros2 = [[0 for x in range(l)] for y in range(m)]
for i in range(n):
    retsu = [int(x) for x in input().split( )]
    zeros1[i] = retsu
for j in range(m):
    retsu2 = [int(x) for x in input().split( )]
    zeros2[j] = retsu2
answer = []
for i in range(n):
    mini_answer = []
    for j in range(l):
        value = 0
        for k in range(m):
            value += zeros1[i][k]*zeros2[k][j]
        mini_answer.append(value)
    answer.append(mini_answer)
for x in answer:
    print(*x)

Submission status: Accepted

Solution code:
m, n, k = map(int, input().split())
A, B = [], []
for _ in range(m):
    A.append(list(map(int, input().split())))
for _ in range(n):
    B.append(list(map(int, input().split())))

for index, row in enumerate(A):
    ans = []
    for i in range(k):
        col = [rowB[i] for rowB in B]
        ans.append(sum([x * y for x, y in zip(row, col)]))
    print(' '.join(map(str, ans)))

Submission status: Accepted

Solution code:
import sys

(n, m, l) = sys.stdin.readline().rstrip('\r\n').split(' ')
n = int(n)
m = int(m)
l = int(l)

a = []
b = []
c = []
for ii in range(n):
  a.append([int(x) for x in input().rstrip('\r\n').split(' ')])

for ii in range(m):
  b.append([int(x) for x in input().rstrip('\r\n').split(' ')])

for ii in range(n):
  c.append([])
  for jj in range(l):
    c[ii].append(0)
    for kk in range(m):
      c[ii][jj] += a[ii][kk] * b[kk][jj]
    c[ii][jj] = str(c[ii][jj])
  print(' '.join(c[ii]))

Submission status: Accepted

Solution code:
#!/usr/bin/python3
# -*- coding: utf-8 -*-

import sys

n, m, p = map(int, sys.stdin.readline().split())
mat_a = list()
mat_b = list()

for i in range(n):
    mat_a.append(list(map(int, sys.stdin.readline().split())))

for i in range(m):
    mat_b.append(list(map(int, sys.stdin.readline().split())))

mat_c = [[0 for i in range(p)] for k in range(n)]

for row in range(n):
    for col in range(p):
        for k in range(m):
            mat_c[row][col] += mat_a[row][k]*mat_b[k][col]
    str_x = list(map(str, mat_c[row]))
    print(' '.join(str_x))

Submission status: Accepted

Solution code:
n,m,l = [int(x) for x in input().split()]
A = [[int(x) for x in input().split()] for _ in range(n)]
B = [[int(x) for x in input().split()] for _ in range(m)]
ans = []
for i in range(n):
    blocks = []
    for j in range(l):
        block = 0
        for k in range(m):
            block += A[i][k]*B[k][j]
        blocks.append(block)
    ans.append(blocks)
for _ in ans:
    print(*_)

Submission status: Accepted

Solution code:
n,m,l=map(int,input().split())
a=[list(map(int,input().split())) for _ in range(n)]
b=[list(map(int,input().split())) for _ in range(m)]
[print(*x) for x in [[sum(j*k for j,k in zip(x,y)) for y in zip(*b)] for x in a]]

Submission status: Accepted

Solution code:
n, m, l = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(n)]
b = [list(map(int, input().split())) for _ in range(m)]
c = [[0 for i in range(l)] for j in range(n)]

for i in range(n):
    for j in range(l):
        for k in range(m):
            c[i][j] += a[i][k] * b[k][j]
for i in range(n):
    print(" ".join(map(str, c[i])))

Submission status: Accepted

Solution code:
n, m, l = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(n)]
b = [list(map(int, input().split())) for _ in range(m)]
ans = [[0 for _ in range(l)] for _ in range(n)]
for i in range(n) :
    for j in range(l) :
        for k in range(m) :
            ans[i][j] += a[i][k] * b[k][j]
    print(*ans[i], sep = ' ')

Submission status: Accepted

Solution code:
class Matrix:
    def __init__(self, rows, cols, values=None):
        self.rows = rows
        self.cols = cols
        if values is not None:
            self.values = values
        else:
            row = [0 for i in range(cols)]
            self.values = [row[:] for j in range(rows)]

    def row(self, i):
        return self.values[i-1]

    def col(self, j):
        return [row[j-1] for row in self.values]

    def __mul__(self, other):
        assert self.cols == other.rows

        m = self.__class__(self.rows, other.cols)
        for i in range(self.rows):
            for j in range(other.cols):
                m[i, j] = sum(a * b for (a, b) in zip(self.row(i),
                                                      other.col(j)))
        return m

    def __getitem__(self, idx):
        row, col = idx
        return self.values[row-1][col-1]

    def __setitem__(self, idx, val):
        row, col = idx
        self.values[row-1][col-1] = val

    def __str__(self):
        s = []
        for row in self.values:
            s.append(" ".join([str(i) for i in row]))
        return "\n".join(s)


def run():
    n, m, l = [int(v) for v in input().split()]

    m1 = []
    for i in range(n):
        m1.append([int(v) for v in input().split()])

    m2 = []
    for i in range(m):
        m2.append([int(v) for v in input().split()])

    print(Matrix(n, m, m1) * Matrix(m, l, m2))


run()

Submission status: Accepted

Solution code:
n, m, l = map(int, input().split())
a = []
b = []
c = []
for i in range(n):
    c.append([0 for k in range(l)])
for i in range(n):
    a.append(list(map(int, input().split())))
for i in range(m):
    b.append(list(map(int, input().split())))
for s in range(n):
    for t in range(l):
        elm = 0
        for u in range(m):
            elm += a[s][u] * b[u][t]
        c[s][t] = elm
for i in c:
    print(" ".join(map(str, i)))

Submission status: Accepted

Solution code:
n, m, l = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(n)]
b = [list(map(int, input().split())) for _ in range(m)]
[print(*x) for x in [[sum(j*k for j,k in zip(x,y)) for y in zip(*b)] for x in a]]

Submission status: Accepted

Solution code:
n, m, l = map(int, input().split(' '))
i = 0
A = []
while i < n:
    A.append(list(map(int, input().split(' '))))
    i += 1
j = 0
B = []
while j < m:
    B.append(list(map(int, input().split(' '))))
    j += 1
C = []
k = 0
while k < n:
    c0 = []
    p = 0
    while p < l:
        c1 = 0
        q = 0
        while q < m:
            c1 += A[k][q] * B[q][p]
            q += 1
        c0.append(c1)
        p += 1
    C.append(c0)
    k += 1
ans = ''
r = 0
while r < n:
    ans += ' '.join(map(str, C[r])) + '\n'
    r += 1
print(ans[:-1])

Submission status: Accepted

Solution code:
n, m, l = map(int, input().split())
mat_a = []
mat_b = []

for i in range(n):
    mat_a.append(list(map(int, input().split())))
    
for j in range(m):
    mat_b.append(list(map(int, input().split())))
    
for p in range(n):
    mat_c = []
    for q in range(l):
        sum = 0
        for r in range(m):
            sum += mat_a[p][r] * mat_b[r][q]
        mat_c.append(sum)
    print(' '.join(map(str, mat_c)))

Submission status: Accepted

Solution code:
#coding: utf-8

n, m, l = (int(i) for i in input().split())
nm = [[0 for i in range(m)] for j in range(n)]
ml = [[0 for i in range(l)] for j in range(m)]
nl = [[0 for i in range(l)] for j in range(n)]

for i in range(n):
    nm[i] = input().split()

for i in range(n):
    for j in range(m):
        nm[i][j] = int(nm[i][j])

for i in range(m):
    ml[i] = input().split()

for i in range(m):
    for j in range(l):
        ml[i][j] = int(ml[i][j])


for i in range(n):
    for j in range(l):
        for k in range(m):
            nl[i][j] += nm[i][k] * ml[k][j]

for i in range(n):
    for j in range(l):
        print(nl[i][j], end = ' ' if j != l-1 else '\n')

Submission status: Accepted

Solution code:
n, m, l = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(n)]
b = [list(map(int, input().split())) for _ in range(m)]
for i in a:
  c = []
  for j in zip(*b):
    c.append(sum([k * l for k, l in zip(i, j)]))
  print(*c)

Submission status: Accepted

Solution code:
n, m, l = map(int,input().split())

x = []
y = []

for i in range(n):
    a = list(map(int,input().split()))
    x.append(a)
    
for i in range(m):
    b = list(map(int,input().split()))
    y.append(b)

#print(x)
a = 0
b = []
ans = []

for i in range(n):
    for j in range(l):
        for k in range(m):
            a += x[i][k]*y[k][j]
        #print(a)
        b.append(a)
        a = 0
    b = list(map(str, b))
    b = ' '.join(b)
    ans.append(b)
    b = []
        
[print(ans[i]) for i in range(len(ans))]

Submission status: Accepted

Solution code:
n, m, l = map(int, input().split())

mathlist1 = [list(map(int, input().split())) for x in range(n)]
mathlist2 = [list(map(int, input().split())) for y in range(m)]
mathlist3 = list(map(list, zip(*mathlist2)))
mathlist4 = []

for d in mathlist1:
    interim = []
    for e in mathlist3:
        result = 0
        for f, g in zip(d, e):
            result += f * g
        interim.append(result)
    mathlist4.append(interim)

for h in mathlist4:
    print(*h, sep=' ')

Submission status: Accepted

Solution code:
n,m,l = map(int,input().split())
n_list=[] 
m_list = []
c=[[0 for i in range(l)] for j in range(n)]
for i in range(n):
    n_list.append([int(i) for i in input().split()])
for j in range(m):
    m_list.append([int(i) for i in input().split()])
for i in range(n):
    for j in range(l):
        for k in range(m):
            c[i][j]+=n_list[i][k]*m_list[k][j]

for i in range(n):
    print(' '.join(str(i) for i in c[i]))

Submission status: Accepted

Solution code:
n, m, l = map(int, input().split())
a = [list(map(int, input().split())) for i in range(n)]
b = [list(map(int, input().split())) for j in range(m)]
[print(*x) for x in [[sum(j*k for j, k in zip(x, y)) for y in zip(*b)] for x in a]]

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

n, m, l = list(map(int, input().split()))
a = []
b = []

for i in range(n):
    a.append(list(map(int, input().split())))

for i in range(m):
    b.append(list(map(int, input().split())))

for i in range(n):
    for j in range(l):
        mat_sum = 0
        for k in range(m):
            mat_sum += a[i][k] * b[k][j]
        if j == l - 1:
            print('{0}'.format(mat_sum), end='')
        else:
            print('{0} '.format(mat_sum), end='')
    print()

Submission status: Accepted

Solution code:
n,m,l = tuple(int(x) for x in input().split())
R = []
A = [[int(a) for a in input().split()] for i in range(n)]
B = [[] for j in range(l)]

for j in range(m):
    i = input().split()
    [B[k].append(int(i[k])) for k in range(l)]
    
for a in A:
    rs = []
    for j in range(l):
        rs.append(sum([a[r]*B[j][r] for r in range(m)]))
    R.append(rs)
    
for r in R:
    print(" ".join(map(str,r)))

Submission status: Accepted

Solution code:
n, m, l = map(int, input().split())
A = [list(map(int, input().split())) for i in range(n)]
B = [list(map(int, input().split())) for i in range(m)]
Sum = []
key = 0
for i in range(n):
    Sum_s = []
    for j in range(l):
        key = 0
        for k in range(m):
            key += A[i][k] * B[k][j]
        Sum_s.append(key)
    Sum.append(Sum_s)
for i in range(n):
    for j in range(l - 1):
        print(Sum[i][j], end = ' ')
    print(Sum[i][l - 1])

Submission status: Accepted

Solution code:
#! python3
# matrix_multiplication.py

n, m, l = [int(x) for x in input().split(' ')]

mat1 = [[int(x) for x in input().split(' ')] for i in range(n)]
mat2 = [[int(x) for x in input().split(' ')] for j in range(m)]

rst_mat = [[0 for k in range(l)] for i in range(n)]

for i in range(n):
    for k in range(l):
        for j in range(m):
            rst_mat[i][k] += mat1[i][j] * mat2[j][k]

for i in range(n):
    print(' '.join([str(x) for x in rst_mat[i]]))

Submission status: Accepted

Solution code:
n,m,l=map(int,input().split())
a=[list(map(int,input().split()))for _ in[0]*n]
b=[list(map(int,input().split()))for _ in[0]*m]
for c in a:print(*[sum(s*t for s,t in zip(c,l))for l in zip(*b)])

Submission status: Accepted

Solution code:
n,m,l=map(int,input().split())
e=[list(map(int,input().split()))for _ in[0]*(n+m)]
for c in e[:n]:print(*[sum(s*t for s,t in zip(c,l))for l in zip(*e[n:])])

Submission status: Accepted

Solution code:
n,m,l=map(int,input().split())
e=[input().split()for _ in[0]*(n+m)]
for c in e[:n]:print(*[sum(int(s)*int(t)for s,t in zip(c,l))for l in zip(*e[n:])])

Submission status: Accepted

Solution code:
import sys
n,m,l=map(int,input().split())
e=[list(map(int,e.split()))for e in sys.stdin]
for c in e[:n]:print(*[sum(s*t for s,t in zip(c,l))for l in zip(*e[n:])])

Submission status: Accepted

Solution code:
i=input
n,m,l=map(int,i().split())
e=[list(map(int,i().split()))for _ in[0]*(n+m)]
for c in e[:n]:print(*[sum(s*t for s,t in zip(c,l))for l in zip(*e[n:])])

Submission status: Accepted

Solution code:
import sys
e=[list(map(int,e.split()))for e in sys.stdin]
n=e[0][0]+1
for c in e[1:n]:print(*[sum(s*t for s,t in zip(c,l))for l in zip(*e[n:])])

Submission status: Accepted

Solution code:
import sys
e=[list(map(int,e.split()))for e in sys.stdin]
n=e[0][0]+1
for c in e[1:n]:
 t=''
 for l in zip(*e[n:]):t+=f'{sum(s*t for s,t in zip(c,l))} '
 print(t[:-1])

Submission status: Accepted

Solution code:
import sys
e=[list(map(int,e.split()))for e in sys.stdin]
n=e[0][0]+1
t=''
for c in e[1:n]:
 for l in zip(*e[n:]):t+=f'{sum(s*t for s,t in zip(c,l))} '
 t=t[:-1]+'\n'
print(t[:-1])

Submission status: Accepted

Solution code:
import sys
e=[list(map(int,e.split()))for e in sys.stdin]
n=e[0][0]+1
[print(*[sum(s*t for s,t in zip(c,l))for l in zip(*e[n:])])for c in e[1:n]]

Submission status: Accepted

Solution code:
import sys
e=[list(map(int,x.split()))for x in sys.stdin];n=e[0][0]+1
[print(*x)for x in[[sum(s*t for s,t in zip(c,l))for l in zip(*e[n:])]for c in e[1:n]]]

Submission status: Accepted

Solution code:
import sys
e=[list(map(int,x.split()))for x in sys.stdin];n=e[0][0]+1
for c in e[1:n]:print(*[sum([s*t for s,t in zip(c,l)])for l in zip(*e[n:])])

Submission status: Accepted

Solution code:
n,m,l = map(int,input().split())
matrix1 =[[0 for i in range(m)] for j in range(n)]
matrix2 =[[0 for i in range(l)] for j in range(m)]
matrix  =[[0 for i in range(l)] for j in range(n)]
for i in range(n):
    a = list(map(int,input().split()))
    for j in range(m):
        matrix1[i][j] = a[j]
for i in range(m):
    a = list(map(int,input().split()))
    for j in range(l):
        matrix2[i][j] = a[j]
for i in range(n):
    for j in range(m):
        for k in range(l):
            matrix[i][k] += matrix1[i][j] * matrix2[j][k]
for i in range(0,n):
    print(' '.join(str(x) for x in matrix[i]))

Submission status: Accepted

Solution code:
def shu(a,b):
	for i in range(a):
		b[i]=list(map(int,input().split()))
n,m,l = map(int,input().split())
A=[[]for i in range(n)]
B=[[]for i in range(m)]
C=[[0 for i in range(l)]for i in range(n)]
shu(n,A)
shu(m,B)
for k in range(m):
	for i in range(n):
		for j in range(l):
			C[i][j] += (A[i][k]*B[k][j])
for i in range(n):
	print(' '.join(map(str,C[i])))

Submission status: Accepted

Solution code:
n, m, l = map(int, input().split())
a = []
b = []

for i in range(n):
    a.append(list(map(int, input().split())))
for j in range(m):
    b.append(list(map(int, input().split())))

for i in range(n):
    li = []
    for j in range(l):
        su = 0
        for k in range(m):
            su += a[i][k] * b[k][j]
        li.append(su)
    print(" ".join(list(map(str, li))))

Submission status: Accepted

Solution code:
n,m,l=map(int,input().split())
a=[list(map(int,input().split())) for i in range(n)]
b=[list(map(int,input().split())) for j in range(m)]
c=[[0]*l for r in range(n)]
for i in range(n):
    for j in range(l):
        for r in range(m):
            c[i][j]+=a[i][r]*b[r][j]
    print(' '.join(map(str,c[i])))

Submission status: Accepted

Solution code:
n, m, l  = [int(_) for _ in input().split()]
matrix1 = []
for i in range(n):
    matrix1.append([int(_) for _ in input().split()])
matrix2 = []
for i in range(m):
    matrix2.append([int(_) for _ in input().split()])

for i in range(n):
    for j in range(l):
        x = 0
        for k in range(m):
            x += matrix1[i][k] * matrix2[k][j]
        print(x, end=" " if j < l - 1 else "\n")

Submission status: Accepted

Solution code:
n, m, l = map(int, input().split())
A = [[int(num) for num in input().split()] for i in range(n)]
B = [[int(num) for num in input().split()] for i in range(m)]
B = list(zip(*B)) # 列を行に置き換える
C = [[0 for i in range(l)] for j in range(n)]
for i, A_line in enumerate(A):
    for j, B_line in enumerate(B):
        for A_element, B_element in zip(A_line, B_line):
            C[i][j] += A_element * B_element

for line in C:
    for i, element in enumerate(line):
        if i == l - 1:
            print(element)
        else:
            print(element, end=' ')