M_N, K, A = [input() for _ in range(3)] M_N_int = [int(s) for s in M_N.split()] m = M_N_int.pop(0) n = M_N_int.pop(0) k_sp = [int(k) for k in K.split()] a1_sp = A.split() a1_int = [int(s) for s in a1_sp] a = [a1_int] n_n = [i for i in range(n+1)] #n_n.reverse() k_kai = 0 p = 1009 amari = '' def make_list(s): global a for _ in range(s-1): a.append([0]) def list_00(s, t): for i in range(1, s): for _ in range(t-1): a[i].append(0) def make_k(k): global k_kai for j in range(m+1): k_kai += k_sp[j]*p**j return k_kai def make_a(n, n_n): global a for i in range(1, k_kai): #for p in range(len(a[0])):だとうまくいかない for p in range(len(a[0])+1): if n_n is not None and len(n_n)>0: for j in n_n: a[i][p] += a[i-1][j]*a[0][n-j] #print(f"a[{i}][{p}] += a[{i-1}][{j}] * a[0][{n-j}] = {a[i-1][j]} * {a[0][n-j]} -> {a[i][p]}") #n_n.pop(0) n_n.pop(-1) n -= 1 if n_n == []: n_n = [i for i in range(n+1)] #n_n.reverse() n = len(a[0])-1 #print(a[i]) a[i].reverse() #print(a[i]) def make_kai(k_kai, p): global amari #a[-1].reverse() for i in range(len(a1_int)): amari += str(a[k_kai-1][i]%p) if i != len(a1_int)-1: amari += ' ' print(amari) make_k(k_sp) make_list(k_kai) list_00(k_kai, len(a1_int)) #print(a[1]) make_a(n, n_n) #print(a) make_kai(k_kai,p)