QOJ.ac

QOJ

Time Limit: 1 s Memory Limit: 64 MB Total points: 100

#11855. Sunsets

Statistics

Inhabitants of Bytetown love watching sunsets from the roofs of their houses. If a sunset is particularly spectacular, some of them decide to go on the roofs of nearby buildings, so that they have a better view.

Buildings in Bytetown capital are arranged on a grid $ n $ × $ n $. Distance between two points is measured using the Manhattan metric.

John plans to buy a new flat. He is a great admirer of sunsets and he is ready to walk to some other building every day to see this inimitable phenomenon. He would not like, however, to walk further than $ k $ units away from his flat.

Help John decide where to buy his new flat. For a given plan of the city with heights of all buildings specified, construct a new map, which for each building $ a $ specifies the height of the highest building that John can walk to, assuming that he buys a flat in building $ a $.

Write a program which:

  • reads from the standard input the plan of the city with heights of all buildings specified,
  • for each building calculates the height of the highest building located not further than $ k $ units away from it,
  • writes the modified map with calculated heights to the standard output.

As a reminder, the Manhattan distance of two points $(a_x, a_y)$ and $(b_x, b_y))$ is $ρ((a_{x}, a_{y}), (b_{x}, b_{y})) = |a_{x} - b_{x}| + |a_{y} - b_{y}|$.

Input Format

In the first line of the standard input there are two integers $ n $ and $ k $ (1 ≤ $ n $ ≤ 1500, 1 ≤ $ k $ ≤ $ n $), separated by a single space. In each of the following $ n $ lines there are $ n $ non-negative integers not grater than 1 000 000 000, separated by single spaces - they describe the plan of Bytetown.

Output Format

In each of $ n $ lines of standard output there should be $ n $ non-negative integers, separated by single spaces and describing the modified plan of Bytetown.

Example

Input

4 2
1 3 4 5
0 2 2 3
4 1 1 3
6 2 3 0

Output

4 5 5 5
6 4 5 5
6 6 4 5
6 6 6 3
About Issues

We understand that our problem archive is not perfect. If you find any issues with the problem, including the statement, scoring configuration, time/memory limits, test cases, etc.

You may use this form to submit an issue regarding the problem. A problem moderator will review your issue and proceed it properly.

STOP! Before you submit an issue, please READ the following guidelines:

  1. This is not a place to publish a discussion, editorial, or requests to debug your code. Your issue will only be visible by you and problem moderators. Other users will not be able to view or reply your issues.
  2. Do not submit duplicated issues. If you have already submitted one, please wait for an moderator to review it. Submitting multiple issues will not speed up the review process and might cause your account to be banned.
  3. Issues must be filed in English or Chinese only.
  4. Be sure your issue is related to this problem. If you need to submit an issue regarding another problem, contest, category, etc., you should submit it to the corresponding page.

Active Issues 0

No issues in this category.

Closed/Resolved Issues 0

No issues in this category.