Farmer John's cows copied the human game of hopscotch and invented a version of their own. Animals that weigh close to a ton play it, so a round usually ends in a mess, and the cows still gather for it almost every afternoon.
The board is an R×C grid, and every square holds one integer between 1 and K.
A cow starts on the top left square and reaches the bottom right square with a sequence of jumps. A jump from the current square to another square is allowed when all three conditions hold.
Count the different sequences of valid jumps that take a cow from the top left square to the bottom right square. Two sequences count as different when the lists of visited squares differ.
The first line contains R, C, and K. (2≤R≤750, 2≤C≤750, 1≤K≤R×C)
Each of the next R lines contains C integers, all between 1 and K.
Print the number of ways to get from the top left square to the bottom right square, modulo 1000000007.