#include <bits/stdc++.h>
using namespace std;
const int N=1e6+5;
long long n,m,k;
const int mod=1e9+7;
int bb[N];
struct mar
{
int n,m;
long long num[105][105];
};
void init(mar &a)
{
memset(a.num,0,sizeof(a.num));
for(int i=0; i<=k; i++)
{
a.num[i][i]=1;
}
return;
}
void pt(mar a)
{
for(int i=0; i<=k; i++)
{
for(int j=0; j<=k; j++)
{
cout<<a.num[i][j]<<" ";
}
cout<<"\n";
}
cout<<"---------\n";
}
mar operator *(const mar &a,const mar &b)
{
mar ans;
memset(ans.num,0,sizeof(ans.num));
ans.n=a.n;
ans.m=b.m;
for(int i=0; i<ans.n; i++)
{
for(int j=0; j<ans.m; j++)
{
for(int k=0; k<a.m; k++)
{
// if(i>j||i>k||j>k)continue;
ans.num[i][j]=(ans.num[i][j]+((a.num[i][k]*b.num[k][j])%mod))%mod;
}
}
}
return ans;
}
mar binpow(mar a,long long b)
{
mar ans;
ans.n=k;
ans.m=k;
init(ans);
while(b>0)
{
if(b&1)
{
ans=ans*a;
}
a=a*a;
b>>=1;
}
return ans;
}
void solve()
{
cin>>n>>m>>k;
mar a,b,c;
a.n=k;
a.m=k;
b.n=k;
b.m=k;
c.n=k;
c.m=k;
for(int i=1; i<=n; i++)
{
int x;
cin>>x;
a.num[0][x%k]++;
}
for(int i=1; i<=n; i++)
{
int x;
cin>>x;
for(int j=0; j<k; j++)
{
b.num[j][(j+x)%k]++;
}
bb[i]=x;
}
for(int i=1; i<=n; i++)
{
int x;
cin>>x;
x+=bb[i];
c.num[((k-x)+100*k)%k][0]++;
}
// pt(a);
// pt(b);
// pt(binpow(b,m-2));
mar ans=a*binpow(b,m-2)*c;
// pt(ans);
cout<<ans.num[0][0]<<"\n";
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
int tn=1;
// cin>>tn;
while(tn--)
{
solve();
}
}
1009A - Game Shopping | 1657A - Integer Moves |
230B - T-primes | 630A - Again Twenty Five |
1234D - Distinct Characters Queries | 1183A - Nearest Interesting Number |
1009E - Intercity Travelling | 1637B - MEX and Array |
224A - Parallelepiped | 964A - Splits |
1615A - Closing The Gap | 4C - Registration System |
1321A - Contest for Robots | 1451A - Subtract or Divide |
1B - Spreadsheet | 1177A - Digits Sequence (Easy Edition) |
1579A - Casimir's String Solitaire | 287B - Pipeline |
510A - Fox And Snake | 1520B - Ordinary Numbers |
1624A - Plus One on the Subset | 350A - TL |
1487A - Arena | 1520D - Same Differences |
376A - Lever | 1305A - Kuroni and the Gifts |
1609A - Divide and Multiply | 149B - Martian Clock |
205A - Little Elephant and Rozdil | 1609B - William the Vigilant |