Polish version    English version  
  History of OI -> VIII OI 2000/2001 -> Problems


 News
 About Olympic
 History of OI
XVII OI 2009/2010
XVI OI 2008/2009
XV OI 2007/2008
XIV OI 2006/2007
XIII OI 2005/2006
XII OI 2004/2005
XI OI 2003/2004
X OI 2002/2003
IX OI 2001/2002
VIII OI 2000/2001
Stage III - results
Stage II - results
Stage I - results
Problems
Regulations
Organization
Hints
Schedule
Stats
VII OI 1999/2000
VI OI 1998/1999
V OI 1997/1998
IV OI 1996/1997
III OI 1995/1996
II OI 1994/1995
I OI 1993/1994
 OI books
 National team
 Olympic camps
 Photo gallery
 Links
 SIO
 MAIN
VIII Olimpiada Informatyczna 2000/2001

Task: MAP
Author: Tomasz Śmigielski
Density map

I stage contest  

There are given:

  • integers n > r >= 0,
  • F - the table n x n with the numbers from the set {0,1}; columns and lines of the table are numbered from 1 to n; the number in i-th column and j-th line of the table is denoted by F[i, j].

If [i, j] and [i', j'] are two positions in the table F, the distance between them is max(|i - i'|, |j - j'|). 

The table W, n x n, should be computed, where W[i, j] (the number in i-th column and j-th line of the table W) is equal to the sum of all the numbers F[x,y], such that the distance between [x,y] and [i,j] is not greater than r.

Task

Write a program, which:

  • reads integers n, r and the table F from the text file MAP.IN,
  • computes the table W,
  • writes the table W into the text file MAP.OUT. 

Input

In the first line of the text file MAP.IN there are two positive integers separated by a single space: n and r, where 0 <= r < n <= 250. In the following n lines the table F is described. Each of these lines contains n integers from the set {0,1}, separated by single spaces. The i-th number written in (j+1)-st line is equal to F[i, j]. 

Output

The text file MAP.OUT should contain exactly n lines. In the j-th line the values W[1, j]...W[n, j] should be written respectively; they should be separated by single spaces. 

Example

For the input file MAP.IN: 

5 1
1 0 0 0 1
1 1 1 0 0 
1 0 0 0 0 
0 0 0 1 1
0 1 0 0 0

The correct answer is the output file MAP.OUT:

3 4 2 2 1
4 5 2 2 1
3 4 3 3 2
2 2 2 2 2
1 1 2 2 2



Print friendly version