This page is still under construction.

Parts of this page are still being built. What you see may change.

Cow Hopscotch

Time limit1sMemory limit256 MB

Summary
Count paths from the top-left to the bottom-right cell that step strictly down and right onto a different value, modulo 1000000007.
Level

Medium6 of 10

Topics
Dynamic programming, Prefix sum, Matrix
Solved
No attempts yet

Problem

People enjoy playing hopscotch, and Farmer John's cows have invented a variant for themselves. Clumsy animals weighing nearly a ton play it, so cow hopscotch almost always ends in disaster. The cows still set the board up nearly every afternoon.

The board is an R×CR \times C grid (2≤R≤1002 \le R \le 100, 2≤C≤1002 \le C \le 100). Each square holds one integer between 11 and KK (1≤K≤R×C1 \le K \le R \times C). A cow starts on the top-left square and reaches the bottom-right square with a sequence of jumps. A jump is valid only when all three of these conditions hold.

  1. The integer on the destination square differs from the integer on the current square.
  2. The destination square is at least one row below the current square.
  3. The destination square is at least one column to the right of the current square.

Count the different sequences of valid jumps that take a cow from the top-left square to the bottom-right square.

Input

The first line contains the integers RR, CC, and KK.

Each of the next RR lines contains CC integers. All of them are between 11 and KK.

Output

Print on one line the number of different ways to get from the top-left square to the bottom-right square, modulo 10000000071000000007.

Examples2

  1. Example 1

    Input
    4 4 4
    1 1 1 1
    1 3 2 1
    1 2 4 1
    1 1 1 1
    
    Expected output
    5
    
  2. Example 2

    Input
    3 3 9
    1 2 3
    4 5 6
    7 8 9
    
    Expected output
    2