QOJ.ac

QOJ

Time Limit: 2 s Memory Limit: 128 MB Total points: 100

#6581. Game of Doubling

统计

Game of doubling is actually more a puzzle than a game. The game board is a rectangle divided into fields that are unit squares. At the beginning, some fields contain a token, and some do not.

The player's objective is to gather a highest number of tokens in a single field. The only possible move is to locate two fields adjoining sides that contain the same (positive) number of tokens and transfer all tokens from one of these fields onto the other.

Write a program that for a given initial board configuration, would determine for each field the maximum number of tokens a player could accumulate in this field.

Input

The first line contains two integers $n$ and $m$ ($1 \le n,m \le 200$) indicating the number of rows and number of columns of the board. Each of the following $n$ lines contains a sequence of $m$ digits: 0 or 1. The digit 1 indicates a field containing a token, and the digit 0 indicates an empty field.

Output

Your program must output $n$ lines each containing $m$ integers. The $j$-th number in the $i$-th row should indicate the maximum number of tokens that a player could accumulate on the field located at the intersection $i$-th row and $j$-th column, starting from the given initial configuration.

Examples

Input

3 4
0111
1011
1011

Output

0 2 4 4
2 0 4 4
2 0 4 4

Explanation

problem_6581_1.gif

The above example explains how to collect 4 tokens at a field positioned at the intersection of the middle row and the last column.

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.