Under construction

Still being built. Things may change

PlayerUnknown's Battlegrounds

Time limit1.5sMemory limit256 MB

Summary
For each value x, count the subgrids whose minimum equals x, given an n by m grid holding a permutation of 1 to n*m.
Level

Hard8 of 10

Topics
Divide and conquer, Implementation, Brute force, Math
Solved
No attempts yet

Problem

When Rikka was playing PUBG (PlayerUnknown's Battlegrounds), she could not win the game. So this time she decided to use some techniques. With the techniques, Rikka can now see clearly where all players are in the game.

In the game, the map can be denoted as a grid of size n×mn \times m. Rikka uses software that can rate an enemy's combat value based on their performance. Right now there is exactly one enemy in each square, and all enemies' combat values form a permutation of the integers from 11 to n⋅mn \cdot m. Since Rikka is quite a green hand, she always cares about the weakest enemies (the less an enemy's combat value is, the weaker the enemy is).

We denote the square at row ii, column jj as (i,j)(i,j). A subgrid can be defined by ((x1,y1),(x2,y2))((x_1,y_1), (x_2,y_2)), where 1≤x1≤x2≤n1 \le x_1 \le x_2 \le n and 1≤y1≤y2≤m1 \le y_1 \le y_2 \le m, and the subgrid itself is the squares (x,y)(x, y) for which x1≤x≤x2x_1 \le x \le x_2 and y1≤y≤y2y_1 \le y \le y_2. Two subgrids ((x1,y1),(x2,y2))((x_1,y_1), (x_2,y_2)) and ((x1′,y1′),(x2′,y2′))((x_1',y_1'), (x_2',y_2')) are the same if and only if ((x1,y1),(x2,y2))=((x1′,y1′),(x2′,y2′))((x_1,y_1),(x_2,y_2)) = ((x_1',y_1'),(x_2',y_2')).

For now, Rikka wants to know how many subgrids are there such that the weakest enemy's combat value in them is equal to xx. Help her find the answers for all x=1,2,…,n⋅mx = 1, 2, \ldots, n \cdot m.

Input

The first line of input contains two integers nn and mm (1≤n,m≤3001 \le n, m \le 300).

Then follow nn lines. The ii-th of them contains mm integers, where the jj-th integer is the combat value of the enemy in (i,j)(i, j). It is guaranteed that the values form a permutation of the integers from 11 to n⋅mn \cdot m.

Output

Print n⋅mn \cdot m lines, with one integer on each line.

The integer on the ii-th line is the answer for x=ix = i.

Examples1

  1. Example 1

    Input
    2 3
    2 5 1
    6 3 4
    
    Expected output
    6
    4
    5
    1
    1
    1