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:
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 = []
for i in range(n):
    lst = []
    for j in range(l):
        tmp = 0
        for k in range(m):
            tmp += (a[i][k] * b[k][j])
        lst.append(tmp)
    c.append(lst)

for i in range(n):
    for j in range(l):
        if (j == l - 1):
            print(c[i][j])
        else:
            print(f"{c[i][j]} ", end="")

Submission status: Accepted

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

mat_a = []
mat_b = []

for i in range(n):
    array = list(map(int, input().split()))
    mat_a.append(array)
for i in range(m):
    array = list(map(int, input().split()))
    mat_b.append(array)

ans = 0
for i in range(n):
    for k in range(l):
        for j in range(m):
            ans += mat_a[i][j] * mat_b[j][k]
        if k != 0:
            print(' ', end='')
        print('{}' .format(ans), end='')
        ans = 0
    print()

Submission status: Accepted

Solution code:
#初期値の挿入
list_nml = list(map(int, input().split()))
list_nm = list()
list_ml = list()
result_nl = [[0]*list_nml[2] for n in range(list_nml[0])]

#インプットdataの格納
for n in range(list_nml[0]):
    list_nm.append(list(map(int, input().split())))
for m in range(list_nml[1]):
    list_ml.append(list(map(int, input().split())))

#計算
for n in range(list_nml[0]):
    for l in range(list_nml[2]):
        result_temp = 0
        for m in range(list_nml[1]):
            result_temp += list_nm[n][m] * list_ml[m][l]
        result_nl[n][l] = result_temp

#計算結果の表示
for a in result_nl:
    print(*a)

Submission status: Accepted

Solution code:
n,m,l = list(map(int, 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] = list(map(int, input().split() ))
for i in range(m):
 B[i] = list(map(int, input().split() ))

for ni in range(n):
 for li in range(l):
  for mi in range(m):
   C[ni][li] = C[ni][li] + A[ni][mi] * B[mi][li]
 print(" ".join(map(str, C[ni])) )

Submission status: Accepted

Solution code:
n_m,m_l,ans=[],[],[]

first_num=[int(w) for w in input().split()]

for w in range(first_num[0]):
    vector=[]
    for i in range(first_num[2]):
        vector.append(0)
    ans.append(vector)
        

for w in range(first_num[0]):
    n_m.append([int(i) for i in input().split()])

for w in range(first_num[1]):
    m_l.append([int(i) for i in input().split()])

for w in range(first_num[0]):
    for i in range(first_num[1]):
        for n in range(first_num[2]):
            ans[w][n]+=n_m[w][i]*m_l[i][n]
            
for w in range(first_num[0]):
    print(' '.join(map(str,ans[w])))

Submission status: Accepted

Solution code:
n,m,l=map(int,input().split())
A=[]
for i in range(n):
    *Ai,=map(int,input().split())
    A.append(Ai)
B=[]
for i in range(m):
    *Bi,=map(int,input().split())
    B.append(Bi)
for i in range(n):
    Ci=[sum([A[i][j]*B[j][k] for j in range(m)]) for k in range(l)]
    print(*Ci)

Submission status: Accepted

Solution code:
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())))

C = [[0 for i in range(l)] for j in range(n)]

#print(A)
#print(B)
#print(C)

for i in range(n):
    for j in range(l):
       for k in range(m):
            #print(f"i:{i},j:{j},k:{k}")
            C[i][j] += A[i][k] * B[k][j]

for i in C:
    print(*i)

Submission status: Accepted

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

for i in range(n):
  a[i] = list(map(int, input().split()))
for i in range(m):
  b[i] = list(map(int, input().split()))
for i in range(n):
  for k in range(l):
    sum = 0
    for j in range(m):
      sum += a[i][j] * b[j][k]
    c[i][k] = sum
    if k == 0:
      print(c[i][k], end = "")
    else:
      print("", c[i][k], end = "")
  print()

Submission status: Accepted

Solution code:
a = []
b = []

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

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

B = []
for k in range(l):
    BB = []
    for i in b:
        BB.append(i[k])
    B.append(BB)

C = []

for i in range(n):
    CC = []
    for k in range(l):
        CCC = 0
        for j in range(m):
            CCC += a[i][j] * B[k][j]
        CC.append(CCC)
    C.append(CC)

for p in C:
    print(" ".join(map(str,p)))

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 i in range(m):
    B.append(list(map(int, input().split())))
ans = []
for i in range(n):
    li = []
    for j in range(l):
        s = 0
        for k in range(m):
            s += A[i][k] * B[k][j]
        li.append(s)
    ans.append(li)
for a in ans:
    print(' '.join(map(str, a)))

Submission status: Accepted

Solution code:
from copy import deepcopy


class Matrix:
    ZERO = 0
    ONE = 1

    def __init__(self, mat, copy: bool = True):
        assert(len(mat) and len(mat[0]))
        if copy:
            self.mat = deepcopy(mat)
        else:
            self.mat = mat

    def __matmul__(self, other):
        ret = [[self.ZERO] * len(other.mat[0]) for _ in range(len(self.mat))]
        for i in range(len(self.mat)):
            for k in range(len(self.mat[0])):
                for j in range(len(other.mat[0])):
                    ret[i][j] += self.mat[i][k] * other.mat[k][j]
        return Matrix(ret)

    def __pow__(self, k):
        ret = Matrix([[self.ZERO] * len(self.mat[0])
                      for _ in range(len(self.mat))])
        for i in range(len(self.mat)):
            ret.mat[i][i] = self.ONE
        n = Matrix(deepcopy(self.mat))

        while k:
            if k & 1:
                ret = ret.__matmul__(n)
            n = n.__matmul__(n)
            k >>= 1
        return ret

    @property
    def shape(self):
        return len(self.mat), len(self.mat[0])

    def __str__(self):
        return '[{}]\n'.format('\n'.join(str(row) for row in self.mat))


def det(mat: Matrix, mod: int = 998244353) -> int:
    # mat は変更されることに注意。
    ret = 1
    N = mat.shape[0]
    for i in range(N):
        pivot = i
        for j in range(i+1, N):
            if abs(mat.mat[j][i]) > abs(mat.mat[pivot][i]):
                pivot = j
        mat.mat[i], mat.mat[pivot] = mat.mat[pivot], mat.mat[i]
        ret *= mat.mat[i][i] * (-1 if i != pivot else 1)
        ret %= mod
        if not mat.mat[i][i]:
            break
        inv = pow(mat.mat[i][i], mod-2, mod)
        for j in range(i+1, N):
            for k in reversed(range(i, N)):
                mat.mat[j][k] += mod - mat.mat[i][k] * \
                    mat.mat[j][i] % mod * inv % mod
                mat.mat[j][k] %= mod
    return ret


def yosupo():
    # https://judge.yosupo.jp/problem/matrix_det
    N = int(input())
    mat = [[int(x) for x in input().split()] for _ in range(N)]
    print(det(Matrix(mat)))


def aoj_matmul():
    N, M, L = map(int, input().split())
    mat1, mat2 = [], []
    for _ in range(N):
        mat1.append([int(x) for x in input().split()])
    for _ in range(M):
        mat2.append([int(x) for x in input().split()])
    A, B = Matrix(mat1, False), Matrix(mat2, False)
    for row in (A @ B).mat:
        print(*row)


if __name__ == '__main__':
    # yosupo()
    aoj_matmul()

Submission status: Accepted

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

arr_a = []
arr_b = []

for _ in range(n):
    vector = list(map(int, input().split()))
    arr_a.append(vector)
    
for _ in range(m):
    vector = list(map(int, input().split()))
    arr_b.append(vector)

arr_result = [[0 for _ in range(l)] for _ in range(n)]

for i in range(n):
    for j in range(l):
        for k in range(m):
            arr_result[i][j] += arr_a[i][k] * arr_b[k][j]

for arr in arr_result:
    print(" ".join(map(str, arr)))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N,M,L = list(map(int, 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]=list(map(int, input().split()));

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

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 C:
	for j in range(L):
		print(i[j],end="");
		if(j!=L-1):
			print(" ",end="")
	print();

Submission status: Accepted

Solution code:
# n, m, lを受け取る
n, m, l = map(int, input().split())

# 行列Aを受け取る
A = []
for i in range(n):
    A.append(list(map(int, input().split())))

# 行列Bを受け取る
B = []
for j in range(m):
    B.append(list(map(int, input().split())))

# 行列Cの元となる行列を作成
C = [[0 for a in range(l)] for b in range(n)]

# 処理実行
for c in range(n):
    for d in range(l):
        result = 0
        for e in range(m):
            result += A[c][e] * B[e][d]
        C[c][d] = result
for f in C:
    print(" ".join(map(str, f)))

Submission status: Accepted

Solution code:
n, m, l = [int(i) for i in input().split()]
left = [[int(i) for i in input().split()] for _ in range(n)]
right = [[int(i) for i in input().split()] for _ in range(m)]
ans = [[0] * l for _ in range(n)]
for i, left_v in enumerate(left):
    for j, right_v in enumerate(list(zip(*right))):
        ans[i][j] = sum([x * y for (x, y) in zip(left_v, right_v)])
for row in ans:
    print(*row)

Submission status: Accepted

Solution code:
n,m,l = map(int, input().split())
A = []
B = []
for _ in range(n):
    A.append(list(map(int, input().split())))
for _ in range(m):
    B.append(list(map(int, input().split())))
    
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,raw_input().split())
a=[map(int,raw_input().split()) for i in range(n)]
b=[map(int,raw_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):
    for j in range(l):
        print (c[i][j]),
    print

Submission status: Accepted

Solution code:
def calc_matrix_prod(m_a, m_b):

    r_a = len(m_a)
    c_a = len(m_a[0])

    r_b = len(m_b)
    c_b = len(m_b[0])

    res = list()

    for i in range(r_a):
        line = list()
        for j in range(c_b):
            s = 0
            for k in range(c_a):
                s += m_a[i][k] * m_b[k][j]
            
            line.append(s)
        res.append(line)    
    
    for i in range(r_a):
        for j in range(c_b):
            print(str(res[i][j]), end="")

            if j != c_b - 1:
                print(" ", end="")

        print("\n", end="")

if __name__ == "__main__":
    
    param = input().split(" ")
    n = int(param[0])
    m = int(param[1])
    l = int(param[2])

    i = n

    m_a = list()
    m_b = list()

    while(i):

        l = input().split(" ")
        m_a.append([int(n) for n in l])

        i -= 1

    j = m

    while(j):

        l = input().split(" ")
        m_b.append([int(n) for n in l])

        j -= 1

    calc_matrix_prod(m_a, m_b)

Submission status: Accepted

Solution code:
def inner(a, b):
    s = 0
    for i in range(len(a)):
        s += a[i] * b[i]
    return s

def dot(A, B):
    C = []
    for i in range(len(A)):
        c_i = []
        for j in range(len(B)):
            c_i.append(inner(A[i], B[j]))
        C.append(c_i)
    return C

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

A = []
for _ in range(n):
    A.append([int(x) for x in input().split()])

B = [[] for _ in range(l)]
for _ in range(m):
    b_t = [int(x) for x in input().split()]
    for i in range(l):
        B[i].append(b_t[i])
        
C = dot(A, B)

for i in range(n):
    for j in range(l):
        print(C[i][j], end="")
        
        if j < l - 1:
            print(" ", end="")
    print()

Submission status: Accepted

Solution code:
n,m,l = map(int,input().split())#n,m,lの入力
#n x m の行列を読み込む
A = [[int(i) for i in input().split()]for j in range(n)]

#m x l の行列を読み込む
B = [[int(i) for i in input().split()]for j in range(m)]

#n*lの行列の積をいれる行列Cを定義
C = [[0]*l for i in range(n)]

# C = np.dot(A,B) #行列の積を求める

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][0],end="")
    for j in range(1,l):
        print("",C[i][j],end="")
    print()

Submission status: Accepted

Solution code:
n, m, l = map(int, 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] = list(map(int, input().split()))
for j in range(m):
    B[j] = list(map(int, input().split()))
for x in range(n):
    for y in range(l):
        for z in range(m):
            C[x][y] += A[x][z] * B[z][y]
        if y == l - 1 :
            print(C[x][y], end="")
        else:
            print(C[x][y], 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)]
c = [[0 for i in range(l)] for j in range(n)]

for i in range(n):
    for j in range(l):
        c[i][j] = str(sum(a[i][k] * b[k][j] for k in range(m)))

for i in c:
    print(*i)

Submission status: Accepted

Solution code:
n,m,l=map(int,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] = input().split()
for i in range(m):
    b[i] = input().split()
for i in range(n):
	s = ""
	for j in range(l):
		for k in range(m):
			c[i][j] = c[i][j] + int(a[i][k]) * int(b[k][j])
		if j == 0:
			s = str(c[i][j])
		else:
			s = s + " " + str(c[i][j])
	print(s)

Submission status: Accepted

Solution code:
n,m,l = map(int, 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):
    lst_Arg = input().split()
    for j in range(m):
        A[i][j] = int(lst_Arg[j])

for i in range(m):
    lst_Arg = input().split()
    for j in range(l):
        B[i][j] = int(lst_Arg[j])

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

for i in C:
    print(*i)

Submission status: Accepted

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

a = []

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

b = []

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

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

Submission status: Accepted

Solution code:
n,m,l = map(int,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):
    nums = [int(e) for e in input().split()]
    for j in range(m):
        A[i][j] = nums[j]
for i in range(m):
    nums = [int(e) for e in input().split()]
    for j in range(l):
        B[i][j] = nums[j]
for i in range(n):
    for j in range(l):
        for k in range(m):
            C[i][j] = C[i][j] + A[i][k] * B[k][j]
    print(*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 i in range(m):
    b.append(list(map(int,input().split())))

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

for i in range(len(c)):
    for j in range(len(c[i])):
        print(c[i][j],end="")

        if(j<len(c[i])-1):
            print(" ",end="")
    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)]
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 q in range(n):
    print(*c[q])

Submission status: Accepted

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

#matrixCの初期化(n行l列)
matrixC = [[0 for i in range (l)]for k in range (n)]

#matrixAの入力
for i in range (n): 
    matrixA.append(list(map(int, input().split())))
#matrixBの入力
for j in range (m): 
    matrixB.append(list(map(int, input().split())))

#matrixCの導出
for i in range (n):
    for j in range (m):
        for k in range (l):
            matrixC[i][k] += matrixA[i][j] * matrixB[j][k]

#matrixCの出力
for i in range (n):
    print(" ".join(map(str, matrixC[i])))

Submission status: Accepted

Solution code:

n,m,l=map(int,input().split())
a=[[]for i in range(n)]
b=[[]for i in range(m)]
c=[[0]*l for i in range(n)]
for i in range(n):
    a[i]=list(map(int,input().split()))
for i in range(m):
    b[i]=list(map(int,input().split()))
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 e in c:
    print(*e)

Submission status: Accepted

Solution code:
n, m, l = list(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 k in range(l)] for o in range(n)]
ans = 0

for a in range(n):
    for b in range(l):
        ans = 0
        for c in range(m):
            ans += matrix_a[a][c] * matrix_b[c][b]
        matrix_c[a][b] = ans       

for matrix in matrix_c:
    print(*matrix)

Submission status: Accepted

Solution code:
def multiply(list1, list2):
    sum = 0
    for s in range(len(list1)):
        sum += int(list1[s] * list2[s])
    return sum


n, m, l = map(int, input().split())
list1 = [[0]*(m) for i in range(n)]
list2 = [[0]*(l) for i in range(m)]
list3 = [[0]*(l) for i in range(n)]
for i in range(n):
    list4 = list(map(int,input().split()))
    for j in range(m):
        list1[i][j] = list4[j]


for i in range(m):
    list4 = list(map(int,input().split()))
    for j in range(l):
        list2[i][j] = list4[j]


for i in range(n):
    for j in range(l):
        list3[i][j] = multiply([list1[i][x] for x in range(m)], [list2[x][j] for x in range(m)])
        if j==l-1:
            print(list3[i][j], end='')
        else:
            print(list3[i][j], end=' ')
    print()

Submission status: Accepted

Solution code:
lst_input = list(map(int, input().split()))
n, m, l = lst_input[0], lst_input[1], lst_input[2]

matrix_A = []
matrix_B = []
matrix_C = [[0 for i in range (l)] for j in range(n)]

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

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

for i in range(n):
    for j in range(l):
        for k in range(m):
            matrix_C[i][j] = matrix_C[i][j] + matrix_A[i][k] * matrix_B[k][j]

for i in matrix_C:
    for j, k in enumerate(i):
        if j == l - 1:
            print(k)
        else:
            print(k, end= " ")

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 j in range(l)] for i in range(n)]

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

for c in C:
    print(*c)

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 _ in range(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(' '.join(map(str, C[i])))

Submission status: Accepted

Solution code:
# coding=utf-8

###
### for python program
###

import sys
import math

# math class
class mymath:
    ### pi
    pi = 3.14159265358979323846264338

    ### Prime Number
    def pnum_eratosthenes(self, n):
        ptable = [0 for i in range(n+1)]
        plist = []

        for i in range(2, n+1):
            if ptable[i]==0:
                plist.append(i)
                for j in range(i+i, n+1, i):
                    ptable[j] = 1
        return plist

    def pnum_check(self, n):
        if (n==1):
            return False
        elif (n==2):
            return True
        else:
            for x in range(2,n):
                if(n % x==0):
                    return False
            return True

    ### GCD
    def gcd(self, a, b):
        if b == 0:
            return a
        return self.gcd(b, a%b)

    ### LCM
    def lcm(self, a, b):
        return (a*b)//self.gcd(a,b)

    ### Mat Multiplication
    def mul(self, A, B):
        ans = []
        for a in A:
            c = 0
            for j, row in enumerate(a):
                c += row*B[j]
            ans.append(c)
        return ans
    
    ### intチェック
    def is_integer(self, n):
        try:
            float(n)
        except ValueError:
            return False
        else:
            return float(n).is_integer()

    ### 幾何学問題用
    def dist(self, A, B):
        d = 0
        for i in range(len(A)):
            d += (A[i]-B[i])**2            
        d = d**(1/2)
        return d

    ### 絶対値
    def abs(self, n):
        if n >= 0:
            return n
        else:
            return -n

mymath = mymath()

### output class
class output:
    ### list
    def list(self, l):
        l = list(l)
        #print(" ", end="")
        for i, num in enumerate(l):
            print(num, end="")
            if i != len(l)-1:
                print(" ", end="")
        print()

output = output()

### input sample
#i = input()
#N = int(input())
#A, B, C = [x for x in input().split()]
#N, K = [int(x) for x in input().split()]
#inlist = [int(w) for w in input().split()]

#R = float(input())
#A.append(list(map(int,input().split())))

#for line in sys.stdin.readlines():
#    x, y = [int(temp) for temp in line.split()]

#abc list
#abc = [chr(ord('a') + i) for i in range(26)]

### output sample
# print("{0} {1} {2:.5f}".format(A//B, A%B, A/B))
# print("{0:.6f} {1:.6f}".format(R*R*math.pi,R*2*math.pi))
# print(" {}".format(i), end="")

def printA(A):
    N = len(A)
    for i, n in enumerate(A):
        print(n, end='')
        if i != N-1:
            print(' ', end='')
    print()

# リスト内包表記 ifあり
# [x-k if x != 0 else x for x in C]

# ソート（代入する必要なし）
# N.sort()

# 10000個の素数リスト
# P = mymath.pnum_eratosthenes(105000)

def get_input():
    N = []
    while True:
        try:
            N.append(input())
            #N.append(int(input()))
            #N.append(float(input()))
            #N.append([int(x) for x in input().split()])
        except EOFError:
            break
    return N

#D = get_input()

#p = 0
#s = ''

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

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

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

#print(A)
#print(B)

C = []

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

for i in C:
    printA(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:
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")

def main():
    h0,w0h1,w1 = map(int, input().split())
    aa=[list(map(int, input().split())) for _ in range(h0)]
    bb=[list(map(int, input().split())) for _ in range(w0h1)]
    for ar in aa:
        print(*[sum(a*b for a,b in zip(ar,bc)) for bc in zip(*bb)])

main()

Submission status: Accepted

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

for i in range(n):
    x = [ int(s) for s in input().split() ]
    a[i][:m] = x

for i in range(m):
    y = [ int(s) for s in input().split() ]
    b[i][:l] = y

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

for i in range(n):
    print(*c[i])

Submission status: Accepted

Solution code:
import sys

BIG_NUM = 2000000000
MOD = 1000000007
EPS = 0.000000001


N,M,L = map(int,input().split())

A = [list(map(int,input().split())) for i in range(N)] #N*M配列の取得
B = [list(map(int,input().split())) for i in range(M)] #M*L配列の取得
ANS = [[0]*L for i in range(N)] #N*L


for x in range(N):
    for y in range(L):
        for z in range(M):
            ANS[x][y] += B[z][y]*A[x][z]

for row in range(N):
    print("%d"%ANS[row][0],end = "")
    for col in range(1,L):
        print(" %d"%(ANS[row][col]),end = "")
    print()

Submission status: Accepted

Solution code:
n, l, m = map(int, input().split())
matrixA = [[0] * (l) for i in range(n)]
matrixB = [[0] * (m) for i in range(l)]
matrix = [[0] * (m) for i in range(n)]

for i in range(0, n):
    listnum = input().split()
    for j in range (0, l):
        matrixA[i][j] = listnum[j]

for i in range(0, l):
    listnum = input().split()
    for j in range (0, m):
        matrixB[i][j] = listnum[j]

for i in range(0,n):
    for j in range(0,m):
        s = 0
        for k in range(0,l):
            s = s + int(matrixA[i][k])*int(matrixB[k][j])
            matrix[i][j] = str(s)

for i in range(0, n):
    print(" ".join(matrix[i]))

Submission status: Accepted

Solution code:
a, b, c = map(int, input().split())

A = [list(map(int, input().split())) for _ in range(a)]
B = [list(map(int, input().split())) for _ in range(b)]

for i in range(a):
    for j in range(c):
        tmp = 0
        for k in range(b):
            tmp += A[i][k] * B[k][j]

        print(tmp, end="")

        if j != c-1:
            print(" ", end="")
    print()

Submission status: Accepted

Solution code:
n, m, l = map(int, input().split())
A = []
B = []
for _ in range(n):
    A.append(list(map(int, input().split())))
for _ in range(m):
    B.append(list(map(int, input().split())))
    
C = [[0 for _ in range(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 c in C:
    print(*c)

Submission status: Accepted

Solution code:
N, M, L = [int(i) for i in input().split()]

A = []
for n in range(N):
    A.append([int(a) for a in input().split()])
    
B = []
for m in range(M):
    B.append([int(b) for b in input().split()])
    
C = [[0]*L for _ in range(N)]
for n in range(N):
    for l in range(L):
        v = 0
        for m in range(M):
            v += A[n][m] * B[m][l]
        C[n][l] = v
        
for n in range(N):
    print(*C[n])

Submission status: Accepted

Solution code:
n,m,l=list(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=[]
for i in range(n):
    row=[]
    for j in range(l):
        ele=0
        for k in range(m):
            ele+=A[i][k]*B[k][j]
        row.append(ele)
    C.append(row)
for i in C:
    print(*i)

Submission status: Accepted

Solution code:
n,m,l = map(int, input().split())
mA = [[0 for i in range(m)] for j in range(n)]
mB = [[0 for i in range(l)] for j in range(m)]
mC = [[0 for i in range(l)] for j in range(n)]
for i in range(n):
  mA[i] = list(map(int, input().split()))
for j in range(m):
  mB[j] = list(map(int, input().split()))
for i in range(n):
  for j in range(l):
    for k in range(m):
      mC[i][j] += mA[i][k]*mB[k][j]
  print(" ".join(map(str, mC[i])))

Submission status: Accepted

Solution code:
# http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP1_7_D&lang=ja

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]*l for _ in range(n)]

# print(A)
# print(B)
# print(C)

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 = []
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):
        tmp = 0
        for k in range(m):
            tmp += a[i][k]*b[k][j]
        if j == l-1:
            print(str(tmp))
        else:
            print(str(tmp) + ' ', end='')

Submission status: Accepted

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