a farmer rectangular grid land m row n column divide unit cell each cell fertile represent 1 barren represent 0 all cell outside grid consider barrena pyramidal plot land define set cell follow criteriaThe number cell set great 1 cell fertileThe apex pyramid topmost cell pyramid the height pyramid number row cover let r c apex pyramid height h then plot comprise cell j r r h 1 c r j c run inverse pyramidal plot land define set cell similar criteriaThe number cell set great 1 cell fertileThe apex inverse pyramid bottommost cell inverse pyramid the height inverse pyramid number row cover let r c apex pyramid height h then plot comprise cell j r h 1 r c r j c r iSome example valid invalid pyramidal inverse pyramidal plot show black cell indicate fertile cellsGiven 0indexe m x n binary matrix grid represent farmland return total number pyramidal inverse pyramidal plot find grid Example 1input grid 01101111output 2explanation the 2 possible pyramidal plot show blue red respectivelythere inverse pyramidal plot grid hence total number pyramidal inverse pyramidal plot 2 0 2example 2input grid 111111output 2explanation the pyramidal plot show blue inverse pyramidal plot show red hence total number plot 1 1 2example 3input grid 11110111111111101001output 13explanation there 7 pyramidal plot 3 show 2nd 3rd figuresThere 6 inverse pyramidal plot 2 show figureThe total number plot 7 6 13 Constraintsm gridlengthn gridilength1 m n 10001 m n 105gridij 0 1