matrix_polynomial

(256000 kilobytes, 1000 milliseconds)

Submissions: 0 · Accepted: 0

Submit code

Statement

Polynomial of a matrix

Work modulo \(p=1\,000\,000\,007\). Given an (n\times n) matrix (A) and

\[ f(x)=c_0+c_1x+\cdots+c_dx^d, \]

compute

\[ f(A)=c_0I+c_1A+\cdots+c_dA^d\pmod p. \]

Input

The first line contains (n,d). The next (n) lines contain (A). The final
line contains (c_0,c_1,\ldots,c_d).

Output

Print (f(A)) as (n) rows of (n) integers modulo (p).

Constraints