Under construction

Still being built. Things may change

Matrix power

Interview

Time limit1sMemory limit256 MB

Summary
Compute the N by N matrix A raised to power B, with each entry reduced modulo 1000.
Level

Easy3 of 10

Topics
Matrix, Divide and conquer
Solved
No attempts yet

Problem

You are given an N×NN \times N matrix AA and an exponent BB. Write a program that computes ABA^B.

The entries can grow very large, so print each entry of ABA^B modulo 1,000.

Input

The first line contains the matrix size NN and the exponent BB, separated by a space. (2≤N≤52 \le N \le 5, 1≤B≤100,000,000,0001 \le B \le 100{,}000{,}000{,}000)

Each of the next NN lines contains one row of AA. Every entry is 0 or a positive integer not greater than 1,000.

Output

Print ABA^B on NN lines. Line ii holds the NN entries of row ii separated by single spaces, each reduced modulo 1,000.

Examples3

  1. Example 1

    Input
    2 5
    1 2
    3 4
    
    Expected output
    69 558
    337 406
    
  2. Example 2

    Input
    3 3
    1 2 3
    4 5 6
    7 8 9
    
    Expected output
    468 576 684
    62 305 548
    656 34 412
    
  3. Example 3

    Input
    5 10
    1 0 0 0 1
    1 0 0 0 1
    1 0 0 0 1
    1 0 0 0 1
    1 0 0 0 1
    
    Expected output
    512 0 0 0 512
    512 0 0 0 512
    512 0 0 0 512
    512 0 0 0 512
    512 0 0 0 512