Matrix Rotation

Time Limit: 2000/1000 MS (Java/Others)

Memory Limit: 32768/32768 K (Java/Others)

Description

Give you a n*n matrix, if you rotate it 90 degrees, we call it 1-Matrix, if you rotate it 180 degrees, we call it 2-Matrix, etc … This is said if you rotate the Matrix 90*k degrees, then we call it k-Matrix. Now, your task is to calculate all the sum of i-Matrix (0<= i<= k).

Input

There multiple test cases. Each test case begins with one integer n(1 <= n <= 10), following n lines, each line contains n integers, describe the original matrix, then a single line contains a k
(1 <= k <= 10^8)described above. Process to end of file.

Output

For each case, output the sum of all the i-Matrix (0<= i<= k) in n lines.
Each line there are n integers separated by one space.
Note that there is no extra space at the end of each line.

Sample Input

3 1 2 3 2 3 4 3 4 5 10

Sample Output

33 32 31 34 33 32 35 34 33

Hint

yifenfei

Source

ZJFC 2009-3 Programming Contest

提交代码