Lucky Chances

Count over every grid cell how many of the four directions contain only smaller numbers or reach the edge.

Easy2Brute forceMatrixImplementationInterviewNo attempts yetTime limit2sMemory limit256 MB

Problem

Lucky Chances is a lottery game. Every ticket has a play field and a scratch area. The play field is a rectangular r×cr \times c grid filled with numbers. The scratch area hides the row number and the column number of the bet cell.

There are four winning directions: up, down, left and right. You win a direction if every number lying in that direction from the bet cell is strictly smaller than the number in the bet cell. If the bet cell sits on the border of the grid, the direction that points off the grid has no number to check, so you win it outright.

Unscratched ticket

Scratched ticket 1

Scratched ticket 2

Larry wants the ticket whose total number of winning directions over all possible bet cells is as large as possible. Given the grid, write a program that determines this total.

Input

The first line contains two integers rr and cc, the number of rows and columns of the grid (1r,c1001 \le r, c \le 100).

Each of the following rr lines contains cc integers, the numbers printed on the grid. Every number is positive and at most 1000.

Output

Print a single integer ww, the total number of winning directions of the given grid.