PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#PS0000230. Tổng hình dấu cộng (Cross Sum Matrix)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Tổng hình dấu cộng (Cross Sum Matrix)

Cross Sum Matrix

Source: Phước Hưng OJ

Version: Phuoc Hung OJ Extended

Problem Statement

Given an integer m×nm\times n matrix and radius KK, for each cell (r,c)(r,c) sum all cells in its row with ∣j−c∣≤K|j-c|\le K and in its column with ∣i−r∣≤K|i-r|\le K. Clip to the matrix boundaries and count the center once. Output the resulting matrix.

Input

The first line contains m,n,Km,n,K, followed by mm rows of nn integers.

Output

Print mm lines of nn cross sums each, in column order.

Subtasks

  • Subtask 1 (20 points): 1≤m,n≤121\le m,n\le 12; −109≤ai,j≤109-10^9\le a_{i,j}\le10^9; 0≤K≤m+n0\le K\le m+n.
  • Subtask 2 (30 points): 1≤m,n≤5001\le m,n\le 500; −109≤ai,j≤109-10^9\le a_{i,j}\le10^9; 0≤K≤m+n0\le K\le m+n; K=0K=0.
  • Subtask 3 (50 points): 1≤m,n≤5001\le m,n\le 500; −109≤ai,j≤109-10^9\le a_{i,j}\le10^9; 0≤K≤m+n0\le K\le m+n.

Example 1

Input

2 3 1
1 2 3
4 5 6

Output

7 11 11
10 17 14

Explanation

Cell (1,2) includes 1,2,3,5, sum 11; cell (2,2) includes 4,5,6,2, sum 17.

Example 2

Input

1 2 0
-7 5

Output

-7 5

Explanation

Radius zero keeps only the center.