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.

Discussions

About Discussions

The discussion section is only for posting: Editorials, General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues. Submitting multiple issues may cause your account to be banned.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.