题目传送门
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define re register
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define P pair<int,int>
const int N=1e9;
const int mod=1e9+7;
void read(int &a)
{
a=0;
int d=1;
char ch;
while(ch=getchar(),ch>'9'||ch<'0')
if(ch=='-')
d=-1;
a=ch-'0';
while(ch=getchar(),ch>='0'&&ch<='9')
a=a*10+ch-'0';
a*=d;
}
void write(int x)
{
if(x<0)
putchar(45),x=-x;
if(x>9)
write(x/10);
putchar(x%10+'0');
}
int f[805][805][20][2],a[805][805];
int main()
{
int n,m,k;
read(n);
read(m);
read(k);
k++;
for(re int i=1;i<=n;i++)
for(re int j=1;j<=m;j++)
read(a[i][j]),f[i][j][a[i][j]%k][0]=1;
for(re int i=1;i<=n;i++)
for(re int j=1;j<=m;j++)
for(re int h=0;h<=k;h++)
{
f[i][j][h][0]=(f[i][j][h][0]+f[i-1][j][(h-a[i][j]+k)%k][1])%mod;
f[i][j][h][0]=(f[i][j][h][0]+f[i][j-1][(h-a[i][j]+k)%k][1])%mod;
f[i][j][h][1]=(f[i][j][h][1]+f[i-1][j][(h+a[i][j])%k][0])%mod;
f[i][j][h][1]=(f[i][j][h][1]+f[i][j-1][(h+a[i][j])%k][0])%mod;
}
ll ans=0;
for(re int i=1;i<=n;i++)
for(re int j=1;j<=m;j++)
ans=(ans+f[i][j][0][1])%mod;
printf("%lld",ans);
return 0;
}