{"trustable":true,"sections":[{"title":"","value":{"format":"HTML","content":"\u003cp\u003eZhe the bully, is condemned by all kinds of evil, like bullying those who are weaker. His teammates have been mistreated for a long time. Finally, they decided not to put up with their buddy any more and flee to Digital Village, with the bully in hot pursuit. Due to difficult terrain and a considerable amount of Digital Paths staggered, they can\u0027t be easily arrested.\u003c/p\u003e\n\u003cp\u003eGetting familiar with the terrain as soon as possible is important for these innocents to escape the threat of bullying. All they need now is to count the number of Digital Paths in Digital Village.\u003c/p\u003e\n\u003cp\u003eTo simplify the problem, Digital Village is abstracted into a grid with $n$ rows and $m$ columns filled by integers. A Digital Path is a continuous walk in the grid satisfying the following conditions:\u003c/p\u003e\n\u003cul\u003e\n \u003cli\u003eadjacent boxes in the walk share a common edge;\u003c/li\u003e\n \u003cli\u003ethe walk is maximal, which cannot be extended;\u003c/li\u003e\n \u003cli\u003ethe walk contains at least four boxes;\u003c/li\u003e\n \u003cli\u003egoing from one end to the other, the increment of values for any two adjacent boxes is exactly one.\u003c/li\u003e\n\u003c/ul\u003e\n\u003cp\u003eHere we have some examples.\u003c/p\u003e\n\u003cp\u003e\u003cimg src\u003d\"CDN_BASE_URL/36edf7cfebf114590da21198424850f5?v\u003d1666083741\" alt\u003d\"\"\u003e\u003c/p\u003e\n\u003cp\u003eThe path in Figure 1 is invalid because its length is less than $4$.\u003c/p\u003e\n\u003cp\u003e\u003cimg src\u003d\"CDN_BASE_URL/d531ca68b3c9a80cd610042f6b142157?v\u003d1666083741\" alt\u003d\"\"\u003e\u003c/p\u003e\n\u003cp\u003eThe path in Figure 2 is invalid because it is not continuous.\u003c/p\u003e\n\u003cp\u003e\u003cimg src\u003d\"CDN_BASE_URL/6cdf09349ca4708d1a3c70ef93919404?v\u003d1666083741\" alt\u003d\"\"\u003e\u003c/p\u003e\n\u003cp\u003eThe path in Figure 3 is invalid because it can be extended further.\u003c/p\u003e\n\u003cp\u003e\u003cimg src\u003d\"CDN_BASE_URL/4e1ff27c4f12d3dfdf846ab05eb685b5?v\u003d1666083741\" alt\u003d\"\"\u003e\u003c/p\u003e\n\u003cp\u003eThe path in Figure 4 is also invalid because values in the path are not strictly increased by one.\u003c/p\u003e\n\u003cp\u003e\u003cimg src\u003d\"CDN_BASE_URL/e23425968bb2e943c246220ef91f96a3?v\u003d1666083741\" alt\u003d\"\"\u003e\u003c/p\u003e\n\u003cp\u003eDigital Paths may partially overlap. In Figure 5, there are $4$ Digital Paths marked by different colours.\u003c/p\u003e\n\u003ch3\u003eInput\u003c/h3\u003e\n\u003cp\u003eThe first line contains two positive integers $n$ and $m~(1\\le n,m\\le 1000)$ describing the size of the grid.\u003c/p\u003e\n\u003cp\u003eEach of the next $n$ lines contains $m$ integers, the $j$-th of which, denoted by $a_{i,j}~(-10^7\\le a_{i,j}\\le 10^7)$, represents the value of the box in the $i$-th row and the $j$-th column.\u003c/p\u003e\n\u003ch3\u003eOutput\u003c/h3\u003e\n\u003cp\u003eOutput the number of Digital Paths modulo $(10^9+7)$.\u003c/p\u003e"}},{"title":"Sample 1","value":{"format":"HTML","content":"\u003ctable class\u003d\u0027vjudge_sample\u0027\u003e\n\u003cthead\u003e\n \u003ctr\u003e\n \u003cth\u003eInput\u003c/th\u003e\n \u003cth\u003eOutput\u003c/th\u003e\n \u003c/tr\u003e\n\u003c/thead\u003e\n\u003ctbody\u003e\n \u003ctr\u003e\n \u003ctd\u003e\u003cpre\u003e3 5\n1 2 3 8 7\n-1 -1 4 5 6\n1 2 3 8 7\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003e4\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n\u003cbr /\u003e"}},{"title":"Sample 2","value":{"format":"HTML","content":"\u003ctable class\u003d\u0027vjudge_sample\u0027\u003e\n\u003cthead\u003e\n \u003ctr\u003e\n \u003cth\u003eInput\u003c/th\u003e\n \u003cth\u003eOutput\u003c/th\u003e\n \u003c/tr\u003e\n\u003c/thead\u003e\n\u003ctbody\u003e\n \u003ctr\u003e\n \u003ctd\u003e\u003cpre\u003e4 4\n1 2 3 4\n2 3 4 3\n3 4 3 2\n4 3 2 1\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003e16\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n\u003cbr /\u003e"}}]}