Doubling game

No attempts yetTime limit10sMemory limit256 MB

Problem

The doubling game is closer to a puzzle than to a game. The board is a rectangle divided into unit square cells. At the start some cells hold one token each and the other cells are empty.

The goal is to pile up as many tokens as possible on a single cell. Only one kind of move is allowed. If two cells that share a side hold the same number of tokens and that number is at least 1, you can move every token of one cell onto the other cell.

Given the starting board, write a program that computes for each cell the largest number of tokens that can be gathered on that cell.

Input

The first line has the number of rows nn and the number of columns mm of the board (1n,m2001 \le n, m \le 200).

Each of the next nn lines has a string of mm digits, each digit 0 or 1. A 1 marks a cell with a token and a 0 marks an empty cell.

Output

Print nn lines with mm integers each, separated by single spaces. The jj-th number on the ii-th line is the largest number of tokens that can be gathered on the cell in row ii and column jj, starting from the given board.

Every cell is counted separately and every cell starts from the same board. Making no move at all is allowed, so a cell that holds a token answers at least 1, and an empty cell answers 0.

Hint

The picture shows how 4 tokens are gathered on the cell in row 2, column 4 of the board in the first example. Move the token in row 1, column 3 onto column 4, which leaves 2 tokens in row 1, column 4. Move the token in row 2, column 3 onto column 4, which leaves 2 tokens in row 2, column 4. The two cells share a side and hold the same number of tokens, so move the 2 tokens of row 1, column 4 onto row 2, column 4 and get 4.