Lucky Chances is a lottery game. Every ticket has a play field and a scratch area. The play field is a rectangular r×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.