/*****************************************************
   *Author*         :  Jstyle
   *Email*          :  1281065596@qq.com
   *Created Time*   :  2017-09-06 10:24
*****************************************************/

#pragma GCC diagnostic error "-std=c++11"
#include <bits/stdc++.h>
using namespace std;
#define mem(a,b) memset(a,b,sizeof(a))
#define FIN freopen("in.txt","r",stdin)
#define IO ios_base::sync_with_stdio(0),cin.tie(0)
#define pb push_back
typedef long long LL;
typedef pair<int, LL> PIR;

const int MAXN = 1e6+5;
const LL mod = 1e9+7;

int n, l;
LL x, m, a[MAXN];

struct Mat {
    LL cnt[105];
} mat, mat1, mat2, mat3;

Mat cal (Mat mt1, Mat mt2) {
    Mat ans;
    mem(ans.cnt, 0);
    for (int i = 0; i < m; ++i) {
        for (int j = 0; j < m; ++j) {
            ans.cnt[(i+j)%m] += mt1.cnt[i]*mt2.cnt[j];
            ans.cnt[(i+j)%m] %= mod;
        }
    }
    return ans;
}

Mat qpow (Mat mt, int t) {
    Mat ans = mt;
    while (t) {
        if (t&1)  ans = cal(ans, mt);
        t >>= 1;
        mt = cal(mt, mt);
    }
    return ans;
}
int main ()
{IO;
    //FIN;
    cin >> n >> l >> m;
    mem(a, 0); mem(mat.cnt, 0); mem(mat1.cnt, 0); mem(mat2.cnt, 0); mem(mat3.cnt, 0);
    for (int i = 1; i <= n; ++i) { cin >> x; mat1.cnt[x%m]++; }
    for (int i = 1; i <= n; ++i) { cin >> x; mat2.cnt[x%m]++; a[i] = x; }
    for (int i = 1; i <= n; ++i) { cin >> x; mat3.cnt[(x+a[i])%m]++; }
    if (l <= 2) mat = cal(mat1, mat3);
    else {
        mat = qpow(mat2, l-3);
        mat = cal(mat, mat1);
        mat = cal(mat, mat3);
    }
    LL ans = 0;
    for (int i = 0; i <= 100; ++i) {
        if (i%m == 0) {
            ans += mat.cnt[i];
            ans %= mod;
        }
    }
    cout << ans << endl;
    return 0;
}


#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#define mod 1000000007
#define maxn 100010
using namespace std;
int a[maxn],n,q,m;
inline int read(){
	register int x=0,f=0,ch=getchar();
	while('0'>ch||ch>'9')f^=ch=='-',ch=getchar();
	while('0'<=ch&&ch<='9')x=(x<<1)+(x<<3)+(ch^'0'),ch=getchar();
	return f?-x:x;
}
struct node
{
    long long num[110];
    node(){
    	memset(num,0,sizeof(num));
	}
}l,r,mid;
node mul(node x,node y)
{
    node aa=node();
    for(int i=0;i<m;i++)
    {
        for(int j=0;j<m;j++)
        {
            int k=(i+j)%m;
            aa.num[k]+=x.num[i]*y.num[j]%mod;
            aa.num[k]%=mod;
        }
    }
    return aa;
}
node qpow(node nod,int k)
{
    node sum=nod;
    k--;
    while(k)
    {
        if(k&1)
        {
            sum=mul(sum,nod);
        }
        k>>=1;
        nod=mul(nod,nod);
    }
    return sum;
}
int main()
{
    l=node();
    r=node();
    mid=node();
    cin>>n>>q>>m;
    for(int i=1;i<=n;i++)
    {
        int x=read();
        l.num[x%m]++;
    }
    for(int i=1;i<=n;i++)
    {
        int x=read();
        a[i]=x;
        mid.num[x%m]++;
    }
    for(int i=1;i<=n;i++) {
        int x=read();
        r.num[(x+a[i])%m]++;
    }
    node nod;
    if(q-2>0){
        nod=qpow(mid,q-2);
        nod=mul(nod,l);
        nod=mul(nod,r);
    }
    else
        nod=mul(l,r);
    long long ans=0;
    for(int j=0;j<=100;j++){
        if(j%m==0){
            ans+=nod.num[j];
            ans%=mod;
        }
    }
    printf("%lld\n",ans);
}


#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#define mod 1000000007
#define maxn 1000010
using namespace std;
int a[maxn],n,q,m;
inline int read(){
	register int x=0,f=0,ch=getchar();
	while('0'>ch||ch>'9')f^=ch=='-',ch=getchar();
	while('0'<=ch&&ch<='9')x=(x<<1)+(x<<3)+(ch^'0'),ch=getchar();
	return f?-x:x;
}
struct node
{
    long long num[110];
    node(){
    	memset(num,0,sizeof(num));
	}
}l,r,mid;
node mul(node x,node y)
{
    node aa=node();
    for(int i=0;i<m;i++)
    {
        for(int j=0;j<m;j++)
        {
            int k=(i+j)%m;
            aa.num[k]+=x.num[i]*y.num[j]%mod;
            aa.num[k]%=mod;
        }
    }
    return aa;
}
node qpow(node nod,int k)
{
    node sum=nod;
    k--;
    while(k)
    {
        if(k&1)
        {
            sum=mul(sum,nod);
        }
        k>>=1;
        nod=mul(nod,nod);
    }
    return sum;
}
int main()
{
    l=node();
    r=node();
    mid=node();
    n=read(),q=read(),m=read();
    for(int i=1;i<=n;i++)
    {
        int x=read();
        l.num[x%m]++;
    }
    for(int i=1;i<=n;i++)
    {
        int x=read();
        a[i]=x;
        mid.num[x%m]++;
    }
    for(int i=1;i<=n;i++) {
        int x=read();
        r.num[(x+a[i])%m]++;
    }
    node nod;
    if(q-2>0){
        nod=qpow(mid,q-2);
        nod=mul(nod,l);
        nod=mul(nod,r);
    }
    else
        nod=mul(l,r);
    long long ans=0;
    for(int j=0;j<=100;j++){
        if(j%m==0){
            ans+=nod.num[j];
            ans%=mod;
        }
    }
    printf("%lld\n",ans);
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

typedef pair<int, int> pii;
typedef long long ll;
typedef vector<int> vi;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define ALL(c) (c).begin(),(c).end()

const ll MOD = 1000000007;

int N, L, M;
int st[1000010], gl[1000010], ct[1000010];
ll num[110];
ll dp[110], res[110], nx[110];
ll ans[110];

int main() {
	scanf("%d %d %d", &N, &L, &M);
	rep(i, N) {
		scanf("%d", &gl[i]);
		++ans[gl[i]];
	}
	rep(i, N) {
		scanf("%d", &ct[i]);
		++num[ct[i]];
	}
	rep(i, N) scanf("%d", &gl[i]);

	int k = L - 2;
	dp[0] = 1;
	rep(i, M) res[i] = num[i];

	while (k > 0) {
		if (k & 1) {
			memset(nx, 0, sizeof(nx));
			rep(i, M) {
				rep(j, M) {
					(nx[(i+j)%M] += dp[i] * res[j]) %= MOD;
				}
			}
			rep(i, M) dp[i] = nx[i];
		}
		memset(nx, 0, sizeof(nx));
		rep(i, M) {
			rep(j, M) {
				(nx[(i+j)%M] += res[i] * res[j]) %= MOD;
			}
		}
		rep(i, M) res[i] = nx[i];
		k /= 2;
	}

	memset(nx, 0, sizeof(nx));
	rep(i, M) {
		rep(j, M) {
			(nx[(i+j)%M] += ans[i] * dp[j]) %= MOD;
		}
	}
	rep(i, M) ans[i] = nx[i];

	memset(nx, 0, sizeof(nx));

	ll ret = 0;

	rep(i, N) {
		int mm = (M + M - gl[i] - ct[i]) % M;
		ret = (ret + ans[mm]) % MOD;
	}

	cout << ret << endl;

	return 0;
}


#include <bits/stdc++.h>
using namespace std;

typedef pair<int, int> pii;
typedef long long ll;
typedef vector<int> vi;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define ALL(c) (c).begin(),(c).end()

const ll MOD = 1000000007;

int N, L, M;
int st[100010], gl[100010], ct[100010];
ll num[110];
ll dp[110], res[110], nx[110];
ll ans[110];

int main() {
	scanf("%d %d %d", &N, &L, &M);
	rep(i, N) {
		scanf("%d", &gl[i]);
		++ans[gl[i]];
	}
	rep(i, N) {
		scanf("%d", &ct[i]);
		++num[ct[i]];
	}
	rep(i, N) scanf("%d", &gl[i]);

	int k = L - 2;
	dp[0] = 1;
	rep(i, M) res[i] = num[i];

	while (k > 0) {
		if (k & 1) {
			memset(nx, 0, sizeof(nx));
			rep(i, M) {
				rep(j, M) {
					(nx[(i+j)%M] += dp[i] * res[j]) %= MOD;
				}
			}
			rep(i, M) dp[i] = nx[i];
		}
		memset(nx, 0, sizeof(nx));
		rep(i, M) {
			rep(j, M) {
				(nx[(i+j)%M] += res[i] * res[j]) %= MOD;
			}
		}
		rep(i, M) res[i] = nx[i];
		k /= 2;
	}

	memset(nx, 0, sizeof(nx));
	rep(i, M) {
		rep(j, M) {
			(nx[(i+j)%M] += ans[i] * dp[j]) %= MOD;
		}
	}
	rep(i, M) ans[i] = nx[i];

	memset(nx, 0, sizeof(nx));

	ll ret = 0;

	rep(i, N) {
		int mm = (M + M - gl[i] - ct[i]) % M;
		ret = (ret + ans[mm]) % MOD;
	}

	cout << ret << endl;

	return 0;
}


#include<iostream>
#include<vector>
#include<map>
#include<string>
#include<set>
#include<iomanip>
#include<utility>
#include<algorithm>
#include <stdio.h>
#include <string.h>
#include<queue>
#include<cmath>
using namespace std;
typedef long long int ll;
typedef vector <vector <ll> > matrix;
#define sz(x) ((ll)(x).size())
#define pb push_back
#define pii pair<ll, ll>
const ll mod = 1e9 + 7;

matrix mul(const matrix &a, const matrix &b, ll p) {
	matrix c(sz(a), vector <ll>(sz(b[0])));
	for (int i = 0; i < sz(a); ++i)
		for (int k = 0; k < sz(b); ++k)
			for (int j = 0; j < sz(b[0]); ++j) {
				c[i][j] = (c[i][j] + a[i][k] * b[k][j]) % p;
			}
	return c;
}

void print_matrix(matrix a) {
	for (int i = 0; i < sz(a); ++i) {
		for (int j = 0; j < sz(a[i]); ++j)
			cout << a[i][j] << " ";
		cout << endl;
	}
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n, l, m;
    cin >> n >> l >> m;
    vector <int> a(n), b(n), c(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
        a[i] %= m;
    }
    for (int i = 0; i < n; ++i) {
        cin >> b[i];
        b[i] %= m;
    }
    for (int i = 0; i < n; ++i) {
        cin >> c[i];
        c[i] %= m;
    }
    matrix aa(m, vector <ll> (m));
    for (int i = 0; i < m; ++i)
        for (int j = 0; j < n; ++j) {
            ++aa[(i + m - b[j]) % m][i];
        }
    matrix ans(m, vector <ll> (m));
    for (int i = 0; i < n; ++i) {
        ++ans[0][a[i]];
    }
    l -= 2;
    while (l) {
        if (l & 1) {
            ans = mul(ans, aa, mod);
        }
        aa = mul(aa, aa, mod);
        l /= 2;
    }
    ll res = 0;
    for (int i = 0; i < n; ++i) {
        res = (res + ans[0][(2 * m - b[i] - c[i]) % m]) % mod;
    }
    cout << res;
    return 0;
}


#include<iostream>
#include<vector>
#include<map>
#include<string>
#include<set>
#include<iomanip>
#include<utility>
#include<algorithm>
#include <stdio.h>
#include <string.h>
#include<queue>
#include<cmath>
using namespace std;
typedef long long int ll;
typedef vector <vector <ll> > matrix;
#define sz(x) ((ll)(x).size())
#define pb push_back
#define pii pair<ll, ll>
const ll mod = 1e9 + 7;
int a[1000005], b[1000005], c[1000005];

int readInt () {
	bool minus = false;
	int result = 0;
	char ch;
	ch = getchar();
	while (true) {
		if (ch == '-') break;
		if (ch >= '0' && ch <= '9') break;
		ch = getchar();
	}
	if (ch == '-') minus = true; else result = ch-'0';
	while (true) {
		ch = getchar();
		if (ch < '0' || ch > '9') break;
		result = result*10 + (ch - '0');
	}
	if (minus)
		return -result;
	else
		return result;
}

matrix mul(const matrix &a, const matrix &b, ll p) {
	matrix c(sz(a), vector <ll>(sz(b[0])));
	for (int i = 0; i < sz(a); ++i)
		for (int k = 0; k < sz(b); ++k)
			for (int j = 0; j < sz(b[0]); ++j) {
				c[i][j] = (c[i][j] + a[i][k] * b[k][j]) % p;
			}
	return c;
}

void print_matrix(matrix a) {
	for (int i = 0; i < sz(a); ++i) {
		for (int j = 0; j < sz(a[i]); ++j)
			cout << a[i][j] << " ";
		cout << endl;
	}
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n, l, m;
    n = readInt();
    l = readInt();
    m = readInt();
    for (int i = 0; i < n; ++i) {
        a[i] = readInt();
        a[i] %= m;
    }
    for (int i = 0; i < n; ++i) {
        b[i] = readInt();
        b[i] %= m;
    }
    for (int i = 0; i < n; ++i) {
        c[i] = readInt();
        c[i] %= m;
    }
    matrix aa(m, vector <ll> (m));
    for (int i = 0; i < m; ++i)
        for (int j = 0; j < n; ++j) {
            ++aa[(i + m - b[j]) % m][i];
        }
    matrix ans(m, vector <ll> (m));
    for (int i = 0; i < n; ++i) {
        ++ans[0][a[i]];
    }
    l -= 2;
    while (l) {
        if (l & 1) {
            ans = mul(ans, aa, mod);
        }
        aa = mul(aa, aa, mod);
        l /= 2;
    }
    ll res = 0;
    for (int i = 0; i < n; ++i) {
        res = (res + ans[0][(2 * m - b[i] - c[i]) % m]) % mod;
    }
    cout << res;
    return 0;
}


#include<iostream>
#include<vector>
#include<map>
#include<string>
#include<set>
#include<iomanip>
#include<utility>
#include<algorithm>
#include <stdio.h>
#include <string.h>
#include<queue>
#include<cmath>
using namespace std;
typedef long long int ll;
typedef vector <vector <ll> > matrix;
#define sz(x) ((ll)(x).size())
#define pb push_back
#define pii pair<ll, ll>
const ll mod = 1e9 + 7;

matrix mul(matrix a, matrix b, ll p) {
	matrix c(sz(a), vector <ll>(sz(b[0])));
	for (int i = 0; i < sz(a); ++i)
		for (int k = 0; k < sz(b); ++k)
			for (int j = 0; j < sz(b[0]); ++j) {
				c[i][j] = (c[i][j] + a[i][k] * b[k][j]) % p;
			}
	return c;
}

void print_matrix(matrix a) {
	for (int i = 0; i < sz(a); ++i) {
		for (int j = 0; j < sz(a[i]); ++j)
			cout << a[i][j] << " ";
		cout << endl;
	}
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n, l, m;
    cin >> n >> l >> m;
    vector <int> a(n), b(n), c(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
        a[i] %= m;
    }
    for (int i = 0; i < n; ++i) {
        cin >> b[i];
        b[i] %= m;
    }
    for (int i = 0; i < n; ++i) {
        cin >> c[i];
        c[i] %= m;
    }
    matrix aa(m, vector <ll> (m));
    for (int i = 0; i < m; ++i)
        for (int j = 0; j < n; ++j) {
            ++aa[(i + m - b[j]) % m][i];
        }
    matrix ans(m, vector <ll> (m));
    for (int i = 0; i < n; ++i) {
        ++ans[0][a[i]];
    }
    l -= 2;
    while (l) {
        if (l & 1) {
            ans = mul(ans, aa, mod);
        }
        aa = mul(aa, aa, mod);
        l /= 2;
    }
    ll res = 0;
    for (int i = 0; i < n; ++i) {
        res = (res + ans[0][(2 * m - b[i] - c[i]) % m]) % mod;
    }
    cout << res;
    return 0;
}


#include<iostream>
#include<vector>
#include<map>
#include<string>
#include<set>
#include<iomanip>
#include<utility>
#include<algorithm>
#include <stdio.h>
#include <string.h>
#include<queue>
#include<cmath>
using namespace std;
typedef long long int ll;
typedef vector <vector <ll> > matrix;
#define sz(x) ((ll)(x).size())
#define pb push_back
#define pii pair<ll, ll>
const ll mod = 1e9 + 7;
int a[1000005], b[1000005], c[1000005];

matrix mul(const matrix &a, const matrix &b, ll p) {
	matrix c(sz(a), vector <ll>(sz(b[0])));
	for (int i = 0; i < sz(a); ++i)
		for (int k = 0; k < sz(b); ++k)
			for (int j = 0; j < sz(b[0]); ++j) {
				c[i][j] = (c[i][j] + a[i][k] * b[k][j]) % p;
			}
	return c;
}

void print_matrix(matrix a) {
	for (int i = 0; i < sz(a); ++i) {
		for (int j = 0; j < sz(a[i]); ++j)
			cout << a[i][j] << " ";
		cout << endl;
	}
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n, l, m;
    cin >> n >> l >> m;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
        a[i] %= m;
    }
    for (int i = 0; i < n; ++i) {
        cin >> b[i];
        b[i] %= m;
    }
    for (int i = 0; i < n; ++i) {
        cin >> c[i];
        c[i] %= m;
    }
    matrix aa(m, vector <ll> (m));
    for (int i = 0; i < m; ++i)
        for (int j = 0; j < n; ++j) {
            ++aa[(i + m - b[j]) % m][i];
        }
    matrix ans(m, vector <ll> (m));
    for (int i = 0; i < n; ++i) {
        ++ans[0][a[i]];
    }
    l -= 2;
    while (l) {
        if (l & 1) {
            ans = mul(ans, aa, mod);
        }
        aa = mul(aa, aa, mod);
        l /= 2;
    }
    ll res = 0;
    for (int i = 0; i < n; ++i) {
        res = (res + ans[0][(2 * m - b[i] - c[i]) % m]) % mod;
    }
    cout << res;
    return 0;
}


#include<cstdio>
#include<vector>
using namespace std;
typedef long long ll;
typedef vector<vector<ll>> matrix;
ll mod = 1e9 + 7;

matrix func(matrix& a, matrix& b) {
	matrix ans;
	ans.assign(a.size(), vector<ll>(b[0].size(), 0));

	for (ll i = 0; i < a.size(); i++) {
		for (ll j = 0; j < b[0].size(); j++) {
			for (ll k = 0; k < b.size(); k++) {
				ans[i][j] += a[i][k] * b[k][j];
				ans[i][j] %= mod;
			}
		}
	}

	return ans;
}

matrix go(matrix& a, ll b) {
	matrix ans;
	ans.assign(a.size(), vector<ll>(a.size(), 0));
	if (b == 0) {
		for (ll i = 0; i < ans.size(); i++)
			ans[i][i] = 1;
		return ans;
	}
	if (b == 1)
		return a;
	matrix tem = func(a, a);
	if (b % 2 == 0) {
		return go(tem, b / 2);
	}
	else {
		matrix temtem = go(tem, b / 2);
		return func(temtem, a);
	}
}

ll n, l, m;

ll kk[1000100];

int main() {
	scanf("%lld%lld%lld", &n, &l, &m);

	matrix a;
	a.assign(1, vector<ll>(m, 0));

	for (ll i = 0; i < n; i++) {
		ll tem;
		scanf("%lld", &tem);
		a[0][tem % m] ++;
	}

	matrix b;
	b.assign(m, vector<ll>(m, 0));

	ll xx[100] = { 0 ,};

	for (ll i = 0; i < n; i++) {
		scanf("%lld", &kk[i]);
		xx[kk[i] % m] ++;
	}

	for (ll i = 0; i < m; i++) {
		for (ll j = 0; j < m; j++) {
			b[i][j] += xx[(j - i + m) % m];
			b[i][j] %= mod;
		}
	}

	matrix mat = go(b, l - 2);

	matrix matmat;
	matmat.assign(m, vector<ll>(m, 0));

	ll c[100] = { 0, };
	for (ll i = 0; i < n; i++) {
		ll tem;
		scanf("%lld", &tem);
		c[(tem + kk[i])%m]++;
	}

	for (ll i = 0; i < m; i++) {
		matmat[i][0] = c[(m - i) % m];
	}

	matrix ans = func(a, func(mat, matmat));

	printf("%lld", ans[0][0]);
}


#include<cstdio>
#include<vector>
using namespace std;
typedef long long ll;
typedef vector<vector<ll>> matrix;
ll mod = 1e9 + 7;

matrix func(matrix& a, matrix& b) {
	matrix ans;
	ans.assign(a.size(), vector<ll>(b[0].size(), 0));

	for (ll i = 0; i < a.size(); i++) {
		for (ll j = 0; j < b[0].size(); j++) {
			for (ll k = 0; k < b.size(); k++) {
				ans[i][j] += a[i][k] * b[k][j];
				ans[i][j] %= mod;
			}
		}
	}

	return ans;
}

matrix go(matrix& a, ll b) {
	matrix ans;
	ans.assign(a.size(), vector<ll>(a.size(), 0));
	if (b == 0) {
		for (ll i = 0; i < ans.size(); i++)
			ans[i][i] = 1;
		return ans;
	}
	if (b == 1)
		return a;
	matrix tem = func(a, a);
	if (b % 2 == 0) {
		return go(tem, b / 2);
	}
	else {
		matrix temtem = go(tem, b / 2);
		return func(temtem, a);
	}
}

ll n, l, m;

ll kk[1000100];

int main() {
	scanf("%lld%lld%lld", &n, &l, &m);

	matrix a;
	a.assign(1, vector<ll>(m, 0));

	for (ll i = 0; i < n; i++) {
		ll tem;
		scanf("%lld", &tem);
		a[0][tem % m] ++;
	}

	matrix b;
	b.assign(m, vector<ll>(m, 0));

	ll xx[100] = { 0 ,};

	for (ll i = 0; i < n; i++) {
		scanf("%lld", &kk[i]);
		xx[kk[i] % m] ++;
	}

	for (ll i = 0; i < m; i++) {
		for (ll j = 0; j < m; j++) {
			b[i][j] += xx[(j - i + m) % m];
			b[i][j] %= mod;
		}
	}

	matrix mat = go(b, l - 2);

	matrix matmat;
	matmat.assign(m, vector<ll>(m, 0));

	ll c[100] = { 0, };
	for (ll i = 0; i < n; i++) {
		ll tem;
		scanf("%lld", &tem);
		c[(tem + kk[i])%m]++;
	}

	for (ll i = 0; i < m; i++) {
		matmat[i][0] = c[(m - i) % m];
	}
	matrix xxxxx = func(mat, matmat);
	matrix ans = func(a, xxxxx);

	printf("%lld", ans[0][0]);
}


#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define fi first
#define sec second
typedef long long int  ll;
typedef long double  ld;
#define pii pair<ll,ll>
#define pic pair<ll,char>
#define vi vector< ll >
#define vvi vector< vi >
#define vpi vector< pii >
#define vvpi vector< vpi >
#define st  set <ll, greater <ll> >
#define mst  multiset <ll, greater <ll> >
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define mapp  unordered_map <ll, ll>
#define ppii pair< pii, pii >
#define test(t) ll t;cin>>t;while(t--)
#define inarr(n) ll arr[n];for(ll i=0;i<n;i++)cin>>arr[i];
#define ingra(m) vvi arr(100005);for(ll i=0;i<m;i++){ll u,v;cin>>u>>v;arr[u].pb(v);arr[v].pb(u);}
#define mem(a,b) memset(a,b,sizeof(a))
#define inn freopen("input.txt", "r", stdin)
#define outt freopen("output.txt", "w", stdout)
#define all(arr) arr.begin(),arr.end()
ll power(ll x,ll y){ll res = 1;while(y){if(y&1) res = (res*x)%mod;y=y/2,x=(x*x)%mod;}return res%mod;}
ll n,m,l;
ll start[100],endd[100];
ll middle[100];
ll res[100];
int dp[1000000][100];
ll arr[1000000];
ll ar[1000000];
signed main()
{
    fast;
    cin>>n>>l>>m;
    ll i,j;
    for(i=0;i<n;i++)
    {
        ll k;
        cin>>k;
        start[k%m]++;
    }
    for(i=0;i<n;i++)
    {
        ll k;
        cin>>k;
        middle[k%m]++;
        res[k%m]++;
        arr[i] = k;
    }
    for(i=0;i<n;i++)
    {
        cin>>ar[i];
    }
    l-=3;
    while(l)
    {
        if(l&1)
        {
            ll temp[100]={0};
            ll j;
            for(i=0;i<m;i++)
            {
                for(j=0;j<m;j++)
                {
                    temp[(i+j)%m]+=(res[i]*middle[j]%mod);
                    temp[(i+j)%m]%=mod;
                }
            }
            for(i=0;i<m;i++)
                res[i] = temp[i];

        }
        l/=2;
        ll temp[100]={0};
        for(i=0;i<m;i++)
        {
            for(j=0;j<m;j++)
            {
                temp[(i+j)%m]+=(middle[i]*middle[j]%mod);
                temp[(i+j)%m]%=mod;
            }
        }
        for(i=0;i<m;i++)
            middle[i] = temp[i];
    }

    ll temp[100]={0};
    for(i=0;i<m;i++)
    {
        for(j=0;j<m;j++)
        {
            temp[(i+j)%m] = (temp[(i+j)%m] + start[i]*res[j]%mod);
        }
    }
    for(i=0;i<m;i++)
        res[i] = temp[i],temp[i] = 0;
    for(i=0;i<n;i++)
    {
        for(j=0;j<m;j++)
        {
            ll val = (dp[i][j] + res[(j-arr[i]+m)%m])%mod;
            dp[i][j] = val;
        }
    }
    ll ans = 0;
    for(i=0;i<n;i++)
    {
        for(j=0;j<m;j++)
        {
            if((j+ar[i])%m==0)
                ans = (ans + dp[i][j])%mod;
        }
    }
    cout<<ans;
}


#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define fi first
#define sec second
typedef long long int  ll;
typedef long double  ld;
#define pii pair<ll,ll>
#define pic pair<ll,char>
#define vi vector< ll >
#define vvi vector< vi >
#define vpi vector< pii >
#define vvpi vector< vpi >
#define st  set <ll, greater <ll> >
#define mst  multiset <ll, greater <ll> >
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define mapp  unordered_map <ll, ll>
#define ppii pair< pii, pii >
#define test(t) ll t;cin>>t;while(t--)
#define inarr(n) ll arr[n];for(ll i=0;i<n;i++)cin>>arr[i];
#define ingra(m) vvi arr(100005);for(ll i=0;i<m;i++){ll u,v;cin>>u>>v;arr[u].pb(v);arr[v].pb(u);}
#define mem(a,b) memset(a,b,sizeof(a))
#define inn freopen("input.txt", "r", stdin)
#define outt freopen("output.txt", "w", stdout)
#define all(arr) arr.begin(),arr.end()
ll power(ll x,ll y){ll res = 1;while(y){if(y&1) res = (res*x)%mod;y=y/2,x=(x*x)%mod;}return res%mod;}
ll n,m,l;
ll start[100],endd[100];
ll middle[100];
ll res[100];
// int dp[1000000][100];
ll arr[1000000];
ll ar[1000000];
signed main()
{
    fast;
    cin>>n>>l>>m;
    ll i,j;
    for(i=0;i<n;i++)
    {
        ll k;
        cin>>k;
        start[k%m]++;
    }
    for(i=0;i<n;i++)
    {
        ll k;
        cin>>k;
        middle[k%m]++;
        res[k%m]++;
        arr[i] = k;
    }
    for(i=0;i<n;i++)
    {
        cin>>ar[i];
    }
    if(l>=3){
    l-=3;
    while(l)
    {
        if(l&1)
        {
            ll temp[100]={0};
            ll j;
            for(i=0;i<m;i++)
            {
                for(j=0;j<m;j++)
                {
                    temp[(i+j)%m]+=(res[i]*middle[j]%mod);
                    temp[(i+j)%m]%=mod;
                }
            }
            for(i=0;i<m;i++)
                res[i] = temp[i];

        }
        l/=2;
        ll temp[100]={0};
        for(i=0;i<m;i++)
        {
            for(j=0;j<m;j++)
            {
                temp[(i+j)%m]+=(middle[i]*middle[j]%mod);
                temp[(i+j)%m]%=mod;
            }
        }
        for(i=0;i<m;i++)
            middle[i] = temp[i];
    }

    ll temp[100]={0};
    for(i=0;i<m;i++)
    {
        for(j=0;j<m;j++)
        {
            temp[(i+j)%m] = (temp[(i+j)%m] + start[i]*res[j]%mod);
        }
    }
    for(i=0;i<m;i++)
        res[i] = temp[i],temp[i] = 0;
}
else
{
    for(i=0;i<m;i++)
        res[i] = start[i];
}
    ll ans = 0;
    for(i=0;i<m;i++)
    {
        for(j=0;j<n;j++)
        {
            if((i+arr[j]+ar[j])%m==0)
                ans = (ans+res[i])%mod;
        }
    }
    cout<<ans;
}


#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define fi first
#define sec second
typedef long long int  ll;
typedef long double  ld;
#define pii pair<ll,ll>
#define pic pair<ll,char>
#define vi vector< ll >
#define vvi vector< vi >
#define vpi vector< pii >
#define vvpi vector< vpi >
#define st  set <ll, greater <ll> >
#define mst  multiset <ll, greater <ll> >
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define mapp  unordered_map <ll, ll>
#define ppii pair< pii, pii >
#define test(t) ll t;cin>>t;while(t--)
#define inarr(n) ll arr[n];for(ll i=0;i<n;i++)cin>>arr[i];
#define ingra(m) vvi arr(100005);for(ll i=0;i<m;i++){ll u,v;cin>>u>>v;arr[u].pb(v);arr[v].pb(u);}
#define mem(a,b) memset(a,b,sizeof(a))
#define inn freopen("input.txt", "r", stdin)
#define outt freopen("output.txt", "w", stdout)
#define all(arr) arr.begin(),arr.end()
ll power(ll x,ll y){ll res = 1;while(y){if(y&1) res = (res*x)%mod;y=y/2,x=(x*x)%mod;}return res%mod;}
ll n,m,l;
ll start[100],endd[100];
ll middle[100];
ll res[100];
ll dp[1000000][100];
ll arr[1000000];
ll ar[1000000];
signed main()
{
    fast;
    cin>>n>>l>>m;
    ll i,j;
    for(i=0;i<n;i++)
    {
        ll k;
        cin>>k;
        start[k%m]++;
    }
    for(i=0;i<n;i++)
    {
        ll k;
        cin>>k;
        middle[k%m]++;
        res[k%m]++;
        arr[i] = k;
    }
    for(i=0;i<n;i++)
    {
        cin>>ar[i];
    }
    l-=3;
    while(l)
    {
        if(l&1)
        {
            ll temp[100]={0};
            ll j;
            for(i=0;i<m;i++)
            {
                for(j=0;j<m;j++)
                {
                    temp[(i+j)%m]+=(res[i]*middle[j]%mod);
                    temp[(i+j)%m]%=mod;
                }
            }
            for(i=0;i<m;i++)
                res[i] = temp[i];

        }
        l/=2;
        ll temp[100]={0};
        for(i=0;i<m;i++)
        {
            for(j=0;j<m;j++)
            {
                temp[(i+j)%m]+=(middle[i]*middle[j]%mod);
                temp[(i+j)%m]%=mod;
            }
        }
        for(i=0;i<m;i++)
            middle[i] = temp[i];
    }

    ll temp[100]={0};
    for(i=0;i<m;i++)
    {
        for(j=0;j<m;j++)
        {
            temp[(i+j)%m] = (temp[(i+j)%m] + start[i]*res[j]%mod);
        }
    }
    for(i=0;i<m;i++)
        res[i] = temp[i],temp[i] = 0;
    for(i=0;i<n;i++)
    {
        for(j=0;j<m;j++)
        {
            dp[i][j] = (dp[i][j] + res[(j-arr[i]+m)%m])%mod;
        }
    }
    ll ans = 0;
    for(i=0;i<n;i++)
    {
        for(j=0;j<m;j++)
        {
            if((j+ar[i])%m==0)
                ans = (ans + dp[i][j])%mod;
        }
    }
    cout<<ans;
}


#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define fi first
#define sec second
typedef long long int  ll;
typedef long double  ld;
#define pii pair<ll,ll>
#define pic pair<ll,char>
#define vi vector< ll >
#define vvi vector< vi >
#define vpi vector< pii >
#define vvpi vector< vpi >
#define st  set <ll, greater <ll> >
#define mst  multiset <ll, greater <ll> >
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define mapp  unordered_map <ll, ll>
#define ppii pair< pii, pii >
#define test(t) ll t;cin>>t;while(t--)
#define inarr(n) ll arr[n];for(ll i=0;i<n;i++)cin>>arr[i];
#define ingra(m) vvi arr(100005);for(ll i=0;i<m;i++){ll u,v;cin>>u>>v;arr[u].pb(v);arr[v].pb(u);}
#define mem(a,b) memset(a,b,sizeof(a))
#define inn freopen("input.txt", "r", stdin)
#define outt freopen("output.txt", "w", stdout)
#define all(arr) arr.begin(),arr.end()
ll power(ll x,ll y){ll res = 1;while(y){if(y&1) res = (res*x)%mod;y=y/2,x=(x*x)%mod;}return res%mod;}
ll n,m,l;
ll start[100],endd[100];
ll middle[100];
ll res[100];
// int dp[1000000][100];
ll arr[1000000];
ll ar[1000000];
signed main()
{
    fast;
    cin>>n>>l>>m;
    ll i,j;
    for(i=0;i<n;i++)
    {
        ll k;
        cin>>k;
        start[k%m]++;
    }
    for(i=0;i<n;i++)
    {
        ll k;
        cin>>k;
        middle[k%m]++;
        res[k%m]++;
        arr[i] = k;
    }
    for(i=0;i<n;i++)
    {
        cin>>ar[i];
    }
    l-=3;
    while(l)
    {
        if(l&1)
        {
            ll temp[100]={0};
            ll j;
            for(i=0;i<m;i++)
            {
                for(j=0;j<m;j++)
                {
                    temp[(i+j)%m]+=(res[i]*middle[j]%mod);
                    temp[(i+j)%m]%=mod;
                }
            }
            for(i=0;i<m;i++)
                res[i] = temp[i];

        }
        l/=2;
        ll temp[100]={0};
        for(i=0;i<m;i++)
        {
            for(j=0;j<m;j++)
            {
                temp[(i+j)%m]+=(middle[i]*middle[j]%mod);
                temp[(i+j)%m]%=mod;
            }
        }
        for(i=0;i<m;i++)
            middle[i] = temp[i];
    }

    ll temp[100]={0};
    for(i=0;i<m;i++)
    {
        for(j=0;j<m;j++)
        {
            temp[(i+j)%m] = (temp[(i+j)%m] + start[i]*res[j]%mod);
        }
    }
    for(i=0;i<m;i++)
        res[i] = temp[i],temp[i] = 0;
    ll ans = 0;
    for(i=0;i<m;i++)
    {
        for(j=0;j<n;j++)
        {
            if((i+arr[j]+ar[j])%m==0)
                ans = (ans+res[i])%mod;
        }
    }
    cout<<ans;
}


#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define fi first
#define sec second
typedef long long int  ll;
typedef long double  ld;
#define pii pair<ll,ll>
#define pic pair<ll,char>
#define vi vector< ll >
#define vvi vector< vi >
#define vpi vector< pii >
#define vvpi vector< vpi >
#define st  set <ll, greater <ll> >
#define mst  multiset <ll, greater <ll> >
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define mapp  unordered_map <ll, ll>
#define ppii pair< pii, pii >
#define test(t) ll t;cin>>t;while(t--)
#define inarr(n) ll arr[n];for(ll i=0;i<n;i++)cin>>arr[i];
#define ingra(m) vvi arr(100005);for(ll i=0;i<m;i++){ll u,v;cin>>u>>v;arr[u].pb(v);arr[v].pb(u);}
#define mem(a,b) memset(a,b,sizeof(a))
#define inn freopen("input.txt", "r", stdin)
#define outt freopen("output.txt", "w", stdout)
#define all(arr) arr.begin(),arr.end()
ll power(ll x,ll y){ll res = 1;while(y){if(y&1) res = (res*x)%mod;y=y/2,x=(x*x)%mod;}return res%mod;}
ll n,m,l;
ll start[100],endd[100];
ll middle[100];
ll res[100];
int dp[1000000][100];
ll arr[1000000];
ll ar[1000000];
signed main()
{
    fast;
    cin>>n>>l>>m;
    ll i,j;
    for(i=0;i<n;i++)
    {
        ll k;
        cin>>k;
        start[k%m]++;
    }
    for(i=0;i<n;i++)
    {
        ll k;
        cin>>k;
        middle[k%m]++;
        res[k%m]++;
        arr[i] = k;
    }
    for(i=0;i<n;i++)
    {
        cin>>ar[i];
    }
    l-=3;
    while(l)
    {
        if(l&1)
        {
            ll temp[100]={0};
            ll j;
            for(i=0;i<m;i++)
            {
                for(j=0;j<m;j++)
                {
                    temp[(i+j)%m]+=(res[i]*middle[j]%mod);
                    temp[(i+j)%m]%=mod;
                }
            }
            for(i=0;i<m;i++)
                res[i] = temp[i];

        }
        l/=2;
        ll temp[100]={0};
        for(i=0;i<m;i++)
        {
            for(j=0;j<m;j++)
            {
                temp[(i+j)%m]+=(middle[i]*middle[j]%mod);
                temp[(i+j)%m]%=mod;
            }
        }
        for(i=0;i<m;i++)
            middle[i] = temp[i];
    }

    ll temp[100]={0};
    for(i=0;i<m;i++)
    {
        for(j=0;j<m;j++)
        {
            temp[(i+j)%m] = (temp[(i+j)%m] + start[i]*res[j]%mod);
        }
    }
    for(i=0;i<m;i++)
        res[i] = temp[i],temp[i] = 0;
    for(i=0;i<n;i++)
    {
        for(j=0;j<m;j++)
        {
            ll val = (dp[i][j] + res[(j-arr[i]+m)%m])%mod
            dp[i][j] = val;
        }
    }
    ll ans = 0;
    for(i=0;i<n;i++)
    {
        for(j=0;j<m;j++)
        {
            if((j+ar[i])%m==0)
                ans = (ans + dp[i][j])%mod;
        }
    }
    cout<<ans;
}


#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1000000007,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<int,int> P;

typedef vector<ll> Vec;
typedef vector<Vec> Mat;
ll const MOD = 1e9+7;
Mat operator * (Mat const& A, Mat const& B) {
  Mat ret(A.size(), Vec(B[0].size()));
  rep(i,A.size())rep(k,B.size())rep(j,B[0].size())ret[i][j]=(ret[i][j]+A[i][k]*B[k][j])%MOD;
  return ret;
}
Mat pow(Mat A, ll n) {
  Mat ret(A.size(),Vec(A.size()));
  rep(i,A.size())ret[i][i]=1;
  for(;n>0;n>>=1) {
    if(n&1)ret=ret*A;
    A=A*A;
  }
  return ret;
}

void Main() {
  int n,m,t;
  scanf("%d%d%d",&n,&m,&t);
  int v[3][t];mem(v);
  vector<int> g[3];
  rep(i,3) {
    rep(j,n) {
      int x;
      scanf("%d",&x);
      x%=t;
      g[i].pb(x);
      v[i][x]++;
    }
  }
  Mat a=Mat(t,Vec(t)),b=Mat(t,Vec(t));
  rep(i,t) {
    rep(j,t) a[i][(i+j)%t]+=v[1][j];
  }
  a=pow(a,m-2);
  rep(i,t) b[i][i]+=v[0][i];
  a=b*a;
  ll d[t];
  mem(d);
  rep(i,n) d[(g[1][i]+g[2][i])%t]++;
  ll ans=0;
  rep(i,t) {
    rep(j,t) {
      ans+=a[i][(t-j)%t]*d[j];
      ans%=MAX;
    }
  }
  pr(ans);
}

int main(){/*ios::sync_with_stdio(0);cin.tie(0);*/Main();return 0;}


#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1000000007,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<int,int> P;

typedef vector<ll> Vec;
typedef vector<Vec> Mat;
ll const MOD = 1e9+7;
Mat operator * (Mat const& A, Mat const& B) {
  Mat ret(A.size(), Vec(B[0].size()));
  rep(i,A.size())rep(k,B.size())rep(j,B[0].size())ret[i][j]=(ret[i][j]+A[i][k]*B[k][j])%MOD;
  return ret;
}
Mat pow(Mat A, ll n) {
  Mat ret(A.size(),Vec(A.size()));
  rep(i,A.size())ret[i][i]=1;
  for(;n>0;n>>=1) {
    if(n&1)ret=ret*A;
    A=A*A;
  }
  return ret;
}

void Main() {
  ll n,m,t;
  cin >> n >> m >> t;
  vector<int> v[3];
  rep(i,3) {
    rep(j,n) {
      int x;
      R x;
      x%=MAX;
      v[i].pb(x);
    }
  }
  Mat a=Mat(t,Vec(t));
  rep(i,t) {
    rep(j,n) a[i][(i+v[1][j])%t]++;
  }
  a=pow(a,m-2);
  Mat b=Mat(t,Vec(t)),c=Mat(t,Vec(t));
  rep(i,n) {
    b[v[0][i]%t][v[0][i]%t]++;
  }
  a=b*a;
  ll ans=0;
  rep(i,t) {
    rep(j,v[2].size()) {
      ans+=a[i][(t*2-v[2][j]-v[1][j])%t];
      ans%=MAX;
    }
  }
  pr(ans);
}

int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}


#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <deque>
#include <list>
#include <iterator>
#include <functional>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <climits>
#include <ctime>
#include <cassert>
#include <bitset>
#include <unordered_map>
#include <unordered_set>
using namespace std;

typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pld;
typedef pair<short, short> pss;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define pset set <int>*
#define vi vector <long long>
#define vvi vector <vector<long long> >
#define vll vector <ll>
#define sz(a) ((int)(a.size()))
//#define clear(a) memset((a), 0, sizeof (a))
vvi start, finish;
int n, l, m;

const int MOD = 1e9 + 7;

vvi matrix;
vi adding_value;

int norm(int x) {
    while (x >= m) {
        x -= m;
    }
    return x;
}

void form() {
    matrix.assign(m, vi (m));

    vector<int>add;
    add.assign(m, 0);

    for (int i = 0; i < n; i++) {
        int x;
        cin >> x;
        add[x % m]++;
        adding_value.pb(x);
    }

    for (int i = 0; i < m; i++) {
        int x = i;
        int d = add[i];
        for (int j = 0; j < m; j++) {
            matrix[norm(j + x)][j] += d;
        }
    }

}

vvi multy(const vvi& a, const vvi& b) {
    assert(a[0].size() == b.size());
    vvi c;
    c.assign(a.size(), vi(b[0].size()));
    for (int i = 0; i < a.size(); i++)
        for (int j = 0; j < b[0].size(); j++) {
            long long ans = 0;
            for (int k = 0; k < b.size(); k++) {
                ans = (ans + (long long)a[i][k] * b[k][j]) % MOD;
            }
            c[i][j] = (int)ans;
        }
    return c;
}

vvi E(int m) {
    vvi e;
    e.assign(m, vi(m));
    for (int i = 0; i < m; i++){
        e[i][i] = 1;
    }
    return e;
}

vvi _pow(const vvi& a, int deg) {
    if (deg == 0) {
        return E(m);
    }

    if (deg & 1) {
        return multy(_pow(a, deg - 1), a);
    }

    return _pow(multy(a, a), deg / 2);
}

void print(vvi a) {
    cout << endl;
    for (int i = 0; i < a.size(); i++) {
        for (int j = 0; j < a[i].size(); j++) {
            cout << a[i][j] << " ";
        }
        cout << endl;
    }
    cout << endl;
}
int main() {
   // assert(freopen("/Users/skrrydg/ClionProjects/test_sbyt/input.txt", "r", stdin));
   // assert(freopen("/Users/skrrydg/ClionProjects/test_sbyt/output.txt", "w", stdout));
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    cin >> n >> l >> m;
    start.assign(m, vi (1));
    finish.assign(m, vi (1));

    for (int i = 0; i < n; i++) {
        int x;
        cin >> x;
        start[norm(x)][0]++;

    }
    form();
    matrix = _pow(matrix, l - 2);

    vvi res = multy(matrix, start);
    //print(res);

    vector<int> add;
    add.assign(m, 0);
    for (int i = 0; i < n; i++) {
        int x;
        cin >> x;
        add[norm(x + adding_value[i])]++;
    }

    for (int i = 0; i < m; i++) {
        int x = i;
        int d = add[x];
        for (int j = 0; j < m; j++) {
            finish[norm(x + j)][0] += (d * res[j][0]) % MOD;
        }
    }
    //print(finish);
    cout << finish[0][0] % MOD << endl;
    return 0;
}


#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <deque>
#include <list>
#include <iterator>
#include <functional>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <climits>
#include <ctime>
#include <cassert>
#include <bitset>
#include <unordered_map>
#include <unordered_set>
using namespace std;

typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pld;
typedef pair<short, short> pss;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define pset set <int>*
#define vi vector <long long>
#define vvi vector <vector<long long> >
#define vll vector <ll>
#define sz(a) ((int)(a.size()))
//#define clear(a) memset((a), 0, sizeof (a))
vvi start, finish;
int n, l, m;

const int MOD = 1e9 + 7;

vvi matrix;
vi adding_value;

int norm(int x) {
    while (x >= m) {
        x -= m;
    }
    return x;
}

void form() {
    matrix.assign(m, vi (m));

    for (int i = 0; i < n; i++) {
        int x;
        cin >> x;
        adding_value.pb(x);
        for (int j = 0; j < m; j++) {
            matrix[norm(j + x)][j]++;
        }
    }
}

vvi multy(const vvi& a, const vvi& b) {
    assert(a[0].size() == b.size());
    vvi c;
    c.assign(a.size(), vi(b[0].size()));
    for (int i = 0; i < a.size(); i++)
        for (int j = 0; j < b[0].size(); j++) {
            long long ans = 0;
            for (int k = 0; k < b.size(); k++) {
                ans = (ans + (long long)a[i][k] * b[k][j]) % MOD;
            }
            c[i][j] = (int)ans;
        }
    return c;
}

vvi E(int m) {
    vvi e;
    e.assign(m, vi(m));
    for (int i = 0; i < m; i++){
        e[i][i] = 1;
    }
    return e;
}

vvi _pow(const vvi& a, int deg) {
    if (deg == 0) {
        return E(m);
    }

    if (deg & 1) {
        return multy(_pow(a, deg - 1), a);
    }

    return _pow(multy(a, a), deg / 2);
}

void print(vvi a) {
    cout << endl;
    for (int i = 0; i < a.size(); i++) {
        for (int j = 0; j < a[i].size(); j++) {
            cout << a[i][j] << " ";
        }
        cout << endl;
    }
    cout << endl;
}
int main() {
   // assert(freopen("/Users/skrrydg/ClionProjects/test_sbyt/input.txt", "r", stdin));
  //  assert(freopen("/Users/skrrydg/ClionProjects/test_sbyt/output.txt", "w", stdout));
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    cin >> n >> l >> m;
    start.assign(m, vi (1));
    finish.assign(m, vi (1));

    for (int i = 0; i < n; i++) {
        int x;
        cin >> x;
        start[norm(x)][0]++;

    }
    form();
    matrix = _pow(matrix, l - 2);

    vvi res = multy(matrix, start);
    //print(res);

    for (int i = 0; i < n; i++) {
        int x;
        cin >> x;
        for (int j = 0; j < m; j++) {
            finish[norm(adding_value[i] + x + j)][0] += res[j][0];
        }
    }
    //print(finish);
    cout << finish[0][0] % MOD << endl;
    return 0;
}


#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
const ll P = 1000000007;
int m;
const int maxn = 1001000;

struct arr
{
	vector<ll> a;

	arr(int t)
	{
		a.resize(t, 0);
	}

	arr() {}

	arr friend operator *(const arr& a, const arr& b)
	{
		arr ans(m + 1);
		for (int i = 0; i < m; i++)
		{
			for (int j = 0; j < m; j++)
			{
				ans.a[(i + j) % m] += (a.a[i] * b.a[j]) % P;
				ans.a[(i + j) % m] %= P;
			}
		}
		return ans;
	}
};

arr arrPow(const arr& a, int p)
{
	//p != 0
	arr ret;
	if (p == 1)
	{
		return a;
	}
	if (p % 2 == 0)
	{
		ret = arrPow(a, p / 2);
		ret = ret * ret;
		return ret;
	}

	ret = arrPow(a, p - 1);
	ret = ret * a;
	return ret;
}

int Fir[maxn];
int Mid[maxn];
int Ed[maxn];

int main()
{
#ifdef __LOCAL__
	freopen("Binput.txt", "r", stdin);
#endif

	vector<ll> fir;
	vector<ll> ed;
	int n, l;
	cin >> n >> l >> m;
	fir.resize(m + 1, 0);
	ed.resize(m + 1, 0);
	for (int i = 0; i < n; i++)
	{
		int x;
		cin >> x;
		Fir[i] = x;
		fir[x % m]++;
	}
	for (int i = 0; i < n; i++)
	{
		cin >> Mid[i];
	}
	for (int i = 0; i < n; i++)
	{
		int x;
		cin >> x;
		Ed[i] = x;
		ed[x % m]++;
	}

	arr mm(m + 1);
	arr nn(m + 1);
	for (int i = 0; i < n; i++)
	{
		mm.a[Mid[i] % m]++;
	}
	arr tmp(m + 1);
	if (l >= 3)
		tmp = arrPow(mm, l - 2);
	for (int i = 0; i < n; i++)
	{
		nn.a[(Mid[i] + Ed[i]) % m]++;
	}
	if (l >= 3)
		tmp = tmp * nn;
	else
	{
		tmp = nn;
	}
	ll ans = 0;

	for (int i = 0; i < m; i++)
	{
		ans += (fir[i] * tmp.a[m - i]) % P;
		ans %= P;
	}
	cout << ans << endl;
	return 0;
}


#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
const ll P = 1000000007;
int m;
const int maxn = 1001000;

struct arr
{
	vector<ll> a;

	arr(int t)
	{
		a.resize(t, 0);
	}

	arr() {}

	arr friend operator *(const arr& a, const arr& b)
	{
		arr ans(m + 1);
		for (int i = 0; i < m; i++)
		{
			for (int j = 0; j < m; j++)
			{
				ans.a[(i + j) % m] += (a.a[i] * b.a[j]) % P;
				ans.a[(i + j) % m] %= P;
			}
		}
		return ans;
	}
};

arr arrPow(const arr& a, int p)
{
	//p != 0
	arr ret;
	if (p == 1)
	{
		return a;
	}
	if (p % 2 == 0)
	{
		ret = arrPow(a, p / 2);
		ret = ret * ret;
		return ret;
	}

	ret = arrPow(a, p - 1);
	ret = ret * a;
	return ret;
}

int Fir[maxn];
int Mid[maxn];
int Ed[maxn];

int main()
{
#ifdef __LOCAL__
	freopen("Binput.txt", "r", stdin);
#endif

	vector<ll> fir;
	vector<ll> ed;
	int n, l;
	cin >> n >> l >> m;
	fir.resize(m + 1, 0);
	ed.resize(m + 1, 0);
	for (int i = 0; i < n; i++)
	{
		int x;
		cin >> x;
		Fir[i] = x;
		fir[x % m]++;
	}
	for (int i = 0; i < n; i++)
	{
		cin >> Mid[i];
	}
	for (int i = 0; i < n; i++)
	{
		int x;
		cin >> x;
		Ed[i] = x;
		ed[x % m]++;
	}

	arr mm(m + 1);
	arr nn(m + 1);
	for (int i = 0; i < n; i++)
	{
		mm.a[Mid[i] % m]++;
	}
	arr tmp(m + 1);
	if (l >= 3)
		tmp = arrPow(mm, l - 2);
	for (int i = 0; i < n; i++)
	{
		nn.a[(Mid[i] + Ed[i]) % m]++;
	}
	if (l >= 3)
		tmp = tmp * nn;
	else
	{
		tmp = nn;
	}
	ll ans = 0;

	for (int i = 0; i < m; i++)
	{
		ans += (fir[i] * tmp.a[(m - i) % m]) % P;
		ans %= P;
	}
	cout << ans << endl;
	return 0;
}


#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
const ll P = 1000000007;
int m;
const int maxn = 1001000;

struct arr
{
	vector<ll> a;

	arr(int t)
	{
		a.resize(t, 0);
	}

	arr() {}

	arr friend operator *(const arr& a, const arr& b)
	{
		arr ans(m + 1);
		for (int i = 0; i < m; i++)
		{
			for (int j = 0; j < m; j++)
			{
				ans.a[(i + j) % m] += (a.a[i] * b.a[j]) % P;
				ans.a[(i + j) % m] %= P;
			}
		}
		return ans;
	}
};

arr arrPow(const arr& a, int p)
{
	//p != 0
	arr ret;
	if (p == 1)
	{
		return a;
	}
	if (p % 2 == 0)
	{
		ret = arrPow(a, p / 2);
		ret = ret * ret;
		return ret;
	}

	ret = arrPow(a, p - 1);
	ret = ret * a;
	return ret;
}

int Fir[maxn];
int Mid[maxn];
int Ed[maxn];

int main()
{
#ifdef __LOCAL__
	freopen("Binput2.txt", "r", stdin);
#endif

	vector<ll> fir;
	vector<ll> ed;
	int n, l;
	cin >> n >> l >> m;
	fir.resize(m + 1, 0);
	ed.resize(m + 1, 0);
	for (int i = 0; i < n; i++)
	{
		int x;
		scanf("%d", &x);
		Fir[i] = x;
		fir[x % m]++;
	}
	for (int i = 0; i < n; i++)
	{
		scanf("%d", &Mid[i]);
	}
	for (int i = 0; i < n; i++)
	{
		int x;
		scanf("%d", &x);
		Ed[i] = x;
		ed[x % m]++;
	}

	arr mm(m + 1);
	arr nn(m + 1);
	for (int i = 0; i < n; i++)
	{
		mm.a[Mid[i] % m]++;
	}
	arr tmp(m + 1);
	if (l >= 3)
		tmp = arrPow(mm, l - 2);
	for (int i = 0; i < n; i++)
	{
		nn.a[(Mid[i] + Ed[i]) % m]++;
	}
	if (l >= 3)
		tmp = tmp * nn;
	else
	{
		tmp = nn;
	}
	ll ans = 0;

	for (int i = 0; i < m; i++)
	{
		ans += (fir[i] * tmp.a[(m - i) % m]) % P;
		ans %= P;
	}
	cout << ans << endl;
	return 0;
}


#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
const ll P = 1000000007;
int m;
const int maxn = 1001000;

struct arr
{
	vector<ll> a;

	arr(int t)
	{
		a.resize(t, 0);
	}

	arr() {}

	arr friend operator *(const arr& a, const arr& b)
	{
		arr ans(m + 1);
		for (int i = 0; i < m; i++)
		{
			for (int j = 0; j < m; j++)
			{
				ans.a[(i + j) % m] += (a.a[i] * b.a[j]) % P;
				ans.a[(i + j) % m] %= P;
			}
		}
		return ans;
	}
};

arr arrPow(const arr& a, int p)
{
	//p != 0
	arr ret;
	if (p == 1)
	{
		return a;
	}
	if (p % 2 == 0)
	{
		ret = arrPow(a, p / 2);
		ret = ret * ret;
		return ret;
	}

	ret = arrPow(a, p - 1);
	ret = ret * a;
	return ret;
}

int Fir[maxn];
int Mid[maxn];
int Ed[maxn];

int main()
{
#ifdef __LOCAL__
	freopen("Binput.txt", "r", stdin);
#endif

	vector<ll> fir;
	vector<ll> ed;
	int n, l;
	cin >> n >> l >> m;
	fir.resize(m + 1, 0);
	ed.resize(m + 1, 0);
	for (int i = 0; i < n; i++)
	{
		int x;
		cin >> x;
		Fir[i] = x;
		fir[x % m]++;
	}
	for (int i = 0; i < n; i++)
	{
		cin >> Mid[i];
	}
	for (int i = 0; i < n; i++)
	{
		int x;
		cin >> x;
		Ed[i] = x;
		ed[x % m]++;
	}

	arr mm(m + 1);
	arr nn(m + 1);
	for (int i = 0; i < n; i++)
	{
		mm.a[Mid[i] % m]++;
	}
	arr tmp(m + 1);
	if (l >= 3)
		tmp = arrPow(mm, l - 2);
	for (int i = 0; i < n; i++)
	{
		nn.a[(Mid[i] + Ed[i]) % m]++;
	}
	if (l >= 3)
		tmp = tmp * nn;
	else
	{
		tmp = mm * nn;
	}
	ll ans = 0;

	for (int i = 0; i < m; i++)
	{
		ans += (fir[i] * tmp.a[m - i]) % P;
		ans %= P;
	}
	cout << ans << endl;
	return 0;
}


#include<bits/stdc++.h>
#define ts cout<<"ok"<<endl
#define int long long
#define hh puts("")
#define pc putchar
#define mo 1000000007
//#define getchar() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++)
//char buf[1<<21],*p1=buf,*p2=buf;
using namespace std;
const int N=1000005,M=105;
int n,m,P,a[N],b[N],tot;
struct matrix{
	int R,C,ma[M][M];
	void init(){
		memset(ma,0,sizeof(ma));
	}
	void init1(){
		for(int i=0;i<100;i++) ma[i][i]=1;
	}
	friend matrix operator * (matrix A,matrix B){
		matrix res;
		res.init();
		res.R=A.R;
		res.C=B.C;
		for(int i=0;i<A.R;i++)
			for(int j=0;j<B.C;j++)
				for(int k=0;k<A.C;k++)
					res.ma[i][j]=(res.ma[i][j]+A.ma[i][k]*B.ma[k][j])%mo;
		return res;
	}
}ans,jz;
inline int read(){
    int ret=0,ff=1;char ch=getchar();
    while(!isdigit(ch)){if(ch=='-') ff=-1;ch=getchar();}
    while(isdigit(ch)){ret=ret*10+(ch^48);ch=getchar();}
    return ret*ff;
}
void write(int x){if(x<0){x=-x,pc('-');}if(x>9) write(x/10);pc(x%10+48);}
void writeln(int x){write(x),hh;}
void writesp(int x){write(x),pc(' ');}
matrix ksm(matrix A,int p){
	matrix res;
	res.init();
	res.init1();
	res.R=A.R,res.C=A.C;
	while(p){
		if(p&1) res=res*A;
		p>>=1;
		A=A*A;
	}
	return res;
}
signed main(){
	ans.init(),jz.init();
	n=read(),m=read(),P=read();
	ans.R=P,ans.C=1;
	for(int i=1;i<=n;i++) ans.ma[read()%P][0]++;
	for(int i=1;i<=n;i++) b[i]=read()%P;
	jz.R=jz.C=P;
	for(int i=0;i<P;i++)
		for(int j=1;j<=n;j++)
			jz.ma[i][(i-b[j]+P)%P]=1;
	jz=ksm(jz,m-2);
	ans=jz*ans;
	for(int i=1;i<=n;i++){
		int x=read()%P;
		tot=(tot+ans.ma[(P*2-x-b[i])%P][0])%mo;
	}
	write(tot);
	return 0;
}


#include<bits/stdc++.h>
#define ts cout<<"ok"<<endl
#define int long long
#define hh puts("")
#define pc putchar
#define mo 1000000007
//#define getchar() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++)
//char buf[1<<21],*p1=buf,*p2=buf;
using namespace std;
const int N=1000005,M=105;
int n,m,P,a[N],tot;
struct matrix{
	int R,C,ma[M][M];
	void init(){
		memset(ma,0,sizeof(ma));
	}
	void init1(){
		for(int i=0;i<100;i++) ma[i][i]=1;
	}
	friend matrix operator * (matrix A,matrix B){
		matrix res;
		res.init();
		res.R=A.R;
		res.C=B.C;
		for(int i=0;i<A.R;i++)
			for(int j=0;j<B.C;j++)
				for(int k=0;k<A.C;k++)
					res.ma[i][j]=(res.ma[i][j]+A.ma[i][k]*B.ma[k][j])%mo;
		return res;
	}
}ans,jz;
inline int read(){
    int ret=0,ff=1;char ch=getchar();
    while(!isdigit(ch)){if(ch=='-') ff=-1;ch=getchar();}
    while(isdigit(ch)){ret=ret*10+(ch^48);ch=getchar();}
    return ret*ff;
}
void write(int x){if(x<0){x=-x,pc('-');}if(x>9) write(x/10);pc(x%10+48);}
void writeln(int x){write(x),hh;}
void writesp(int x){write(x),pc(' ');}
matrix ksm(matrix A,int p){
	matrix res;
	res.init();
	res.init1();
	res.R=A.R,res.C=A.C;
	while(p){
		if(p&1) res=res*A;
		p>>=1;
		A=A*A;
	}
	return res;
}
signed main(){
	ans.init(),jz.init();
	n=read(),m=read(),P=read();
	ans.R=P,ans.C=1;
	for(int i=1;i<=n;i++) ans.ma[read()%P][0]++;
	for(int i=1;i<=n;i++) a[i]=read()%P;
	jz.R=jz.C=P;
	for(int i=0;i<P;i++)
		for(int j=1;j<=n;j++)
			jz.ma[i][(i-a[j]+P)%P]++;
	jz=ksm(jz,m-2);
	ans=jz*ans;
	for(int i=1;i<=n;i++){
		int x=read()%P;
		tot=(tot+ans.ma[(P*2-x-a[i])%P][0])%mo;
	}
	write(tot);
	return 0;
}


#include <bits/stdc++.h>
#define db double
#define ll long long
#define N 101
#define M 1000000007
#define File freopen("in", "r", stdin)
#define mem(a, b) memset(a, b, sizeof(a))
#define Add(u, v, z) ({f[++l] = (Edge) {v, z, head[u]}; head[u] = l;})
using namespace std;
ll a[N][N], b[N], c[N][N], d[N], f[N], s[N][N], ans = 0;
int n, m, l;
int getint()
{
   int w = 0; char c = getchar();
   while (c > '9' || c < '0') c = getchar();
   while (c >= '0' && c <= '9') { w = w * 10 + c - '0'; c = getchar(); }
   return w;
}
void Mult(ll a[][N], ll b[][N])
{
   mem(c, 0);
   for (int i = 0; i < m; i++)
      for (int j = 0; j < m; j++)
	 for (int k = 0; k < m; k++)
	    c[i][j] += a[i][k] * b[k][j] % M;
   for (int i = 0; i < m; i++)
      for (int j = 0; j < m; j++)
	 a[i][j] = c[i][j] % M;
}
void func(ll a[][N], int k)
{
   mem(s, 0);
   for (int i = 0; i < m; i++) s[i][i] = 1;
   while (k > 0) {
      if (k & 1) Mult(s, a);
      k >>= 1; Mult(a, a);
   }
   for (int i = 0; i < m; i++)
      for (int j = 0; j < m; j++)
	 a[i][j] = s[i][j];
}
int main()
{
   cin >> n >> l >> m;
   for (int i = 1; i <= n; i++) {
      int x = getint();
      b[x % m]++;
   }
   for (int i = 1; i <= n; i++) {
      int x = getint();
      f[i] = x;
      for (int j = 0; j < m; j++) a[j][(j + x) % m]++;
   }
   for (int i = 1; i <= n; i++) {
      int x = getint();
      d[(m - (x + f[i]) % m) % m]++;
   }
   func(a, l - 2);
   for (int i = 0; i < m; i++)
      for (int j = 0; j < m; j++)
	 ans += b[j] * a[j][i] % M * d[i] % M;

   cout << ans % M << endl;
   return 0;
}


#include <bits/stdc++.h>
#define db double
#define ll long long
#define N 101
#define M 1000000007
#define File freopen("in", "r", stdin)
#define mem(a, b) memset(a, b, sizeof(a))
#define Add(u, v, z) ({f[++l] = (Edge) {v, z, head[u]}; head[u] = l;})
using namespace std;
ll a[N][N], b[N], c[N][N], d[N], s[N][N], ans = 0;
int n, m, l, f[1000010];
int getint()
{
   int w = 0; char c = getchar();
   while (c > '9' || c < '0') c = getchar();
   while (c >= '0' && c <= '9') { w = w * 10 + c - '0'; c = getchar(); }
   return w;
}
void Mult(ll a[][N], ll b[][N])
{
   mem(c, 0);
   for (int i = 0; i < m; i++)
      for (int j = 0; j < m; j++)
	 for (int k = 0; k < m; k++)
	    c[i][j] += a[i][k] * b[k][j] % M;
   for (int i = 0; i < m; i++)
      for (int j = 0; j < m; j++)
	 a[i][j] = c[i][j] % M;
}
void func(ll a[][N], int k)
{
   mem(s, 0);
   for (int i = 0; i < m; i++) s[i][i] = 1;
   while (k > 0) {
      if (k & 1) Mult(s, a);
      k >>= 1; Mult(a, a);
   }
   for (int i = 0; i < m; i++)
      for (int j = 0; j < m; j++)
	 a[i][j] = s[i][j];
}
int main()
{
   cin >> n >> l >> m;
   for (int i = 1; i <= n; i++) {
      int x = getint();
      b[x % m]++;
   }
   for (int i = 1; i <= n; i++) {
      int x = getint();
      f[i] = x;
      for (int j = 0; j < m; j++) a[j][(j + x) % m]++;
   }
   for (int i = 1; i <= n; i++) {
      int x = getint();
      d[(m - (x + f[i]) % m) % m]++;
   }
   func(a, l - 2);
   for (int i = 0; i < m; i++)
      for (int j = 0; j < m; j++)
	 ans += b[j] * a[j][i] % M * d[i] % M;

   cout << ans % M << endl;
   return 0;
}


#include <bits/stdc++.h>
using namespace std;

template <typename T> inline void read(T &x){
    char c;
    bool nega=0;
    while((!isdigit(c=getchar()))&&(c!='-'));
    if(c=='-'){
        nega=1;
        c=getchar();
    }
    x=c-48;
    while(isdigit(c=getchar())) x=x*10+c-48;
    if(nega) x=-x;
}
template <typename T> inline void writep(T x){
    if(x>9) writep(x/10);
    putchar(x%10+48);
}
template <typename T> inline void write(T x){
    if(x<0){
        putchar('-');
        x=-x;
    }
    writep(x);
}
template <typename T> inline void writeln(T x){
    write(x);
    putchar('\n');
}
typedef long long ll;
#define se second
#define fi first
#define pb push_back
const int NMAX=105,M=1e9 + 7,NMAX1=1e6 + 5;
struct node {
	int matrix[NMAX][NMAX];
	node(){
		memset(matrix,0,sizeof matrix);
	}
};
int st[NMAX],e[NMAX];
int x[NMAX1];
node base;
int n,l,m;
node mul(node a,node b){
	node temp;
	for(int i=0;i <= m;i++){
		for(int j=0;j <= m;j++){
			for(int k=0;k <= m;k++){
				temp.matrix[i][j]=(temp.matrix[i][j]+(a.matrix[i][k] * 1LL * b.matrix[k][j])%M)%M;
			}
		}
	}
	return temp;
}
node pp(node b,int p){
	if(p==0){
		node emp;
		return emp;
	}
	if(p==1) return b;
	node temp=pp(b,p/2),m=mul(temp,temp);
	if(p&1) return mul(b,m);
	return m;
}
int main(){
    read(n);read(l);read(m);
	for(int i=0;i<n;i++){
        int a;
		read(a);
		st[a]++;
	}
	for(int i=0;i<n;i++){
        int a;
		read(a);
		x[i]=a;
		for(int j=0;j<=m;j++)
			base.matrix[j][(j+a)%m]++;
	}
	for(int i=0;i<n;i++){
        int a;
		read(a);
		e[(a+x[i])%m]++;
	}
	node ans=pp(base,l-2);
	ll res=0;
	if(l==2){
		for(int i=0;i<=m;i++){
			if(!st[i]) continue;
			for(int j=0;j<=m;j++){
				if(!e[j]) continue;
				if((i+j)%m) continue;
				res=(res+(st[i]*1LL*e[j])%M);
			}
		}
	}
	else{
		for(int i=0;i<=m;i++){
			if(!st[i]) continue;
			for(int j=0;j<=m;j++){
				if(!e[j]) continue;
				for(int k=0;k<=m;k++){
				    if((i+j+k)%m) continue;
					res=(res+(((st[i]*1LL*ans.matrix[0][k])%M)*1LL*e[j])% M);
				}
			}
		}
	}
	writeln(res);
}


#include <bits/stdc++.h>
using namespace std;

template <typename T> inline void read(T &x){
    char c;
    bool nega=0;
    while((!isdigit(c=getchar()))&&(c!='-'));
    if(c=='-'){
        nega=1;
        c=getchar();
    }
    x=c-48;
    while(isdigit(c=getchar())) x=x*10+c-48;
    if(nega) x=-x;
}
template <typename T> inline void writep(T x){
    if(x>9) writep(x/10);
    putchar(x%10+48);
}
template <typename T> inline void write(T x){
    if(x<0){
        putchar('-');
        x=-x;
    }
    writep(x);
}
template <typename T> inline void writeln(T x){
    write(x);
    putchar('\n');
}
typedef long long ll;
#define se second
#define fi first
#define pb push_back
const int NMAX=105,M=1e9 + 7,NMAX1=1e6 + 5;
struct node {
	int matrix[NMAX][NMAX];
	node(){
		memset(matrix,0,sizeof matrix);
	}
};
int st[NMAX],e[NMAX];
int x[NMAX1];
node base;
int n,l,m;
node mul(node a,node b){
	node ret;
	for(int i=0;i <= m;i++){
		for(int j=0;j <= m;j++){
			for(int k=0;k <= m;k++){
				ret.matrix[i][j]=(ret.matrix[i][j]+(a.matrix[i][k] * 1LL * b.matrix[k][j])%M)%M;
			}
		}
	}
	return ret;
}
node pp(node b,int p){
	if(p==0){
		node emp;
		return emp;
	}
	if(p==1) return b;
	node temp=pp(b,p/2),m=mul(temp,temp);
	if(p&1) return mul(b,m);
	return m;
}
int main(){
    read(n);read(l);read(m);
	for(int i=0;i<n;i++){
        int a;
		read(a);
		st[a]++;
	}
	for(int i=0;i<n;i++){
        int a;
		read(a);
		x[i]=a;
		for(int j=0;j<=m;j++)
			base.matrix[j][(j+a)%m]++;
	}
	for(int i=0;i<n;i++){
        int a;
		read(a);
		e[(a+x[i])%m]++;
	}
	node ans=pp(base,l-2);
	ll res=0;
	if(l==2){
		for(int i=0;i<=m;i++){
			if(!st[i]) continue;
			for(int j=0;j<=m;j++){
				if(!e[j]) continue;
				if((i+j)%m) continue;
				res=(res+(st[i]*1LL*e[j])%M);
			}
		}
	}
	else{
		for(int i=0;i<=m;i++){
			if(!st[i]) continue;
			for(int j=0;j<=m;j++){
				if(!e[j]) continue;
				for(int k=0;k<=m;k++){
				    if((i+j+k)%m) continue;
					res=(res+((st[i]*1LL*ans.matrix[0][k])%M)*1LL*e[j]);
				}
			}
		}
	}
	writeln(res);
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define pb push_back
#define mp make_pair
const ll base=1e9+7;
ll n,m,l;
ll a[1000001];
struct matrix{
    ll val[101];
    matrix(){
        memset(val,0,sizeof(val));
    }
};
matrix res,cnt;
inline matrix operator * (const matrix &x,const matrix &y){
    matrix tmp;
    for(int i=0;i<m;i++){
        for(int j=0;j<m;j++){
                tmp.val[(i+j)%m]=(tmp.val[(i+j)%m]+(x.val[i]*y.val[j])%base)%base;
        }
    }
    return tmp;
}
inline matrix pw(matrix x,ll p){
    if(p==1) return x;
    matrix tt=pw(x,p/2);
    if(p&1) return tt*tt*x;
    return tt*tt;
}
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    //freopen("852B.inp","r",stdin);
    cin>>n>>l>>m;
    for(int i=1;i<=n;i++){
        ll u;
        cin>>u;
        res.val[u%m]++;
    }
    for(int i=1;i<=n;i++){
        ll u;
        cin>>u;
        cnt.val[u%m]++;
        a[i]=u%m;
    }
    if(l>=3){
        cnt=pw(cnt,l-2);
        res=res*cnt;
    }
    for(int i=1;i<=n;i++){
        ll u;
        cin>>u;
        a[i]=(a[i]+u)%m;
    }
    ll ans=0;
    for(int i=0;i<m;i++){
        for(int j=1;j<=n;j++){
            if((i+a[j])%m==0){
                ans=(ans+res.val[i])%base;
            }
        }
    }
    cout<<ans;
}


#include <bits/stdc++.h>
using namespace std;

template <typename T> inline void read(T &x){
    char c;
    bool nega=0;
    while((!isdigit(c=getchar()))&&(c!='-'));
    if(c=='-'){
        nega=1;
        c=getchar();
    }
    x=c-48;
    while(isdigit(c=getchar())) x=x*10+c-48;
    if(nega) x=-x;
}
template <typename T> inline void writep(T x){
    if(x>9) writep(x/10);
    putchar(x%10+48);
}
template <typename T> inline void write(T x){
    if(x<0){
        putchar('-');
        x=-x;
    }
    writep(x);
}
template <typename T> inline void writeln(T x){
    write(x);
    putchar('\n');
}
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define pb push_back
#define mp make_pair
const ll base=1e9+7;
ll n,m,l;
ll a[1000001];
struct matrix{
    ll val[101];
    matrix(){
        memset(val,0,sizeof(val));
    }
};
matrix res,cnt;
inline matrix operator * (const matrix &x,const matrix &y){
    matrix tmp;
    for(int i=0;i<m;i++){
        for(int j=0;j<m;j++){
                tmp.val[(i+j)%m]=(tmp.val[(i+j)%m]+(x.val[i]*y.val[j])%base)%base;
        }
    }
    return tmp;
}
void pw(ll p){
    for(;p;p/=2,cnt=cnt*cnt){
        if(p&1) res=res*cnt;
    }
}
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    //freopen("852B.inp","r",stdin);
    read(n);read(l);read(m);
    for(int i=1;i<=n;i++){
        int u;
        read(u);
        res.val[u%m]++;
    }
    for(int i=1;i<=n;i++){
        int u;
        read(u);
        cnt.val[u%m]++;
        a[i]=u%m;
    }
    if(l>=3){
        pw(l-2);
    }
    for(int i=1;i<=n;i++){
        int u;
        read(u);
        a[i]=(a[i]+u)%m;
    }
    ll ans=0;
    for(int i=0;i<m;i++){
        for(int j=1;j<=n;j++){
            if((i+a[j])%m==0){
                ans=(ans+res.val[i])%base;
            }
        }
    }
    writeln(ans);
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define pb push_back
#define mp make_pair
const ll base=1e9+7;
ll n,m,l;
ll a[1000001];
struct matrix{
    ll val[101];
    matrix(){
        memset(val,0,sizeof(val));
    }
};
matrix res,cnt;
inline matrix operator * (const matrix &x,const matrix &y){
    matrix tmp;
    for(int i=0;i<m;i++){
        for(int j=0;j<m;j++){
                tmp.val[(i+j)%m]=(tmp.val[(i+j)%m]+(x.val[i]*y.val[j])%base)%base;
        }
    }
    return tmp;
}
void pw(ll p){
    for(;p;p/=2,cnt=cnt*cnt){
        if(p&1) res=res*cnt;
    }
}
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    //freopen("852B.inp","r",stdin);
    cin>>n>>l>>m;
    for(int i=1;i<=n;i++){
        ll u;
        cin>>u;
        res.val[u%m]++;
    }
    for(int i=1;i<=n;i++){
        ll u;
        cin>>u;
        cnt.val[u%m]++;
        a[i]=u%m;
    }
    if(l>=3){
        pw(l-2);
    }
    for(int i=1;i<=n;i++){
        ll u;
        cin>>u;
        a[i]=(a[i]+u)%m;
    }
    ll ans=0;
    for(int i=0;i<m;i++){
        for(int j=1;j<=n;j++){
            if((i+a[j])%m==0){
                ans=(ans+res.val[i])%base;
            }
        }
    }
    cout<<ans;
}


#include<bits/stdc++.h>
using namespace std;
#define pii pair<int,int>
#define fi first
#define se second
#define mk make_pair
#define pb push_back
#define ls l,mid,rt<<1
#define rs mid+1,r,rt<<1|1
#define de(x) cout<< #x<<" = "<<x<<endl
#define dd(x) cout<< #x<<" = "<<x<<" "
#define sf scanf
#define pf printf

__inline int read(){
    char c=getchar();int x=0,f=1;
    while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
    while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}
    return x*f;
}

__inline string next_line(){
	const int SIZE=1100000;static char buf[SIZE+1];static int p=SIZE;
	string res;int f=1;
	while((p<SIZE||(p=0,buf[fread(buf,1,SIZE,stdin)]=0,buf[0]))&&(buf[p]!='\n'&&(res+=buf[p],f=0,1)||f))++p;
	return res;
}

typedef long long ll;
typedef long double ld;
const int INF=0x3f3f3f3f;
const double eps=1e-8;
const double PI=acos(-1.0);
const int MAXN=1e5+5;
const int MOD=1e9+7;

int sgn(double x){
    if(fabs(x)<eps)return 0;
    if(x<0)return -1;
    else return 1;
}

int n,l,m;
struct Mat{
    ll f[105];
    Mat operator *(const Mat b)const{
        Mat c;
        for(int i=0;i<m;i++)c.f[i]=0;
        for(int i=0;i<m;i++){
            for(int j=0;j<m;j++){
                c.f[(i+j)%m]+=f[i]*b.f[j]%MOD;
                c.f[(i+j)%m]%=MOD;
            }
        }
        return c;
    }
}S,C,E;

Mat pw(Mat A,Mat B,int n){
    while(n){
        if(n&1)A=A*B;
        B=B*B;
        n>>=1;
    }
    return A;
}

int t[MAXN];

int main(){
    sf("%d%d%d",&n,&l,&m);
    for(int i=1,x;i<=n;i++){
        sf("%d",&x);
        S.f[x%m]++;
    }
    for(int i=1,x;i<=n;i++){
        sf("%d",&x);
        C.f[x%m]++;
        t[i]=x;
    }
    for(int i=1,x;i<=n;i++){
        sf("%d",&x);
        E.f[(x+t[i])%m]++;
    }
    Mat ans=pw(S,C,l-2)*E;
    //for(int i=0;i<m;i++)pf("%d %lld\n",i,ans.f[i]);
    pf("%I64d\n",ans.f[0]);
}


#include<bits/stdc++.h>
using namespace std;
#define pii pair<int,int>
#define fi first
#define se second
#define mk make_pair
#define pb push_back
#define ls l,mid,rt<<1
#define rs mid+1,r,rt<<1|1
#define de(x) cout<< #x<<" = "<<x<<endl
#define dd(x) cout<< #x<<" = "<<x<<" "
#define sf scanf
#define pf printf

__inline int read(){
    char c=getchar();int x=0,f=1;
    while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
    while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}
    return x*f;
}

__inline string next_line(){
	const int SIZE=1100000;static char buf[SIZE+1];static int p=SIZE;
	string res;int f=1;
	while((p<SIZE||(p=0,buf[fread(buf,1,SIZE,stdin)]=0,buf[0]))&&(buf[p]!='\n'&&(res+=buf[p],f=0,1)||f))++p;
	return res;
}

typedef long long ll;
typedef long double ld;
const int INF=0x3f3f3f3f;
const double eps=1e-8;
const double PI=acos(-1.0);
const int MAXN=1e6+5;
const int MOD=1e9+7;

int sgn(double x){
    if(fabs(x)<eps)return 0;
    if(x<0)return -1;
    else return 1;
}

int n,l,m;
struct Mat{
    ll f[105];
    Mat operator *(const Mat b)const{
        Mat c;
        for(int i=0;i<m;i++)c.f[i]=0;
        for(int i=0;i<m;i++){
            for(int j=0;j<m;j++){
                c.f[(i+j)%m]+=f[i]*b.f[j]%MOD;
                c.f[(i+j)%m]%=MOD;
            }
        }
        return c;
    }
}S,C,E;

Mat pw(Mat A,Mat B,int n){
    while(n){
        if(n&1)A=A*B;
        B=B*B;
        n>>=1;
    }
    return A;
}

int t[MAXN];

int main(){
    sf("%d%d%d",&n,&l,&m);
    for(int i=1,x;i<=n;i++){
        sf("%d",&x);
        S.f[x%m]++;
    }
    for(int i=1,x;i<=n;i++){
        sf("%d",&x);
        C.f[x%m]++;
        t[i]=x;
    }
    for(int i=1,x;i<=n;i++){
        sf("%d",&x);
        E.f[(x+t[i])%m]++;
    }
    Mat ans=pw(S,C,l-2)*E;
    //for(int i=0;i<m;i++)pf("%d %lld\n",i,ans.f[i]);
    pf("%I64d\n",ans.f[0]);
}


#include<bits/stdc++.h>
using namespace std;
#define rep(i,x,y) for(int i=x;i<=y;i++)
const int N=100;
const int mod=1e9+7;
int n,l,m;
int a[1000001];
struct matrix{
	int a[N][N];
	matrix(){memset(a,0,sizeof(a));}
	int*operator[](int x){return a[x];}
};
struct Vector{
	int a[N];
	Vector(){memset(a,0,sizeof(a));}
	int&operator[](int x){return a[x];}
}qwq1,qwq2,qwq3;
int lim;
void inc(int&x,const int&y){(x+=y)>=mod?x-=mod:x;}
int mul(int x,int y){return 1ll*x*y%mod;}
matrix mul(matrix a,matrix b){
	matrix c;
	rep(i,0,lim-1)rep(j,0,lim-1)rep(k,0,lim-1)inc(c[i][j],mul(a[i][k],b[k][j]));
	return c;
}
matrix qpow(matrix base,int t){
	matrix result;rep(i,0,lim-1)result[i][i]=1;
	while(t){
		if(t&1)result=mul(result,base);
		t>>=1,base=mul(base,base);
	}
	return result;
}
Vector mul(Vector a,Vector b){
	Vector c;
	rep(i,0,lim-1)rep(j,0,lim-1)inc(c[(i+j)%m],mul(a[i],b[j]));
	return c;
}
Vector qpow(Vector base,int t){
	Vector result;result[0]=1;
	while(t){
		if(t&1)result=mul(result,base);
		t>>=1,base=mul(base,base);
	}
	return result;
}
int main(){
#ifdef LOCAL
	freopen("testdata.txt","r",stdin);
#endif
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cin>>n>>l>>m;
	lim=m;
	rep(i,1,n){int x;cin>>x;qwq1[x%m]++;}
	rep(i,1,n){int x;cin>>x;a[i]=x;qwq2[x%m]++;}
	rep(i,1,n){int x;cin>>x;qwq3[(a[i]+x)%m]++;}
	Vector result=mul(mul(qwq1,qpow(qwq2,l-2)),qwq3);
	cout<<result[0]<<'\n';
	return 0;
}


#include<cstdio>
#include<vector>
using namespace std;
typedef long long ll;
typedef vector<vector<ll>> matrix;
ll mod = 1e9 + 7;

matrix func(matrix& a, matrix& b) {
	matrix ans;
	ans.assign(a.size(), vector<ll>(b[0].size(), 0));

	for (ll i = 0; i < a.size(); i++) {
		for (ll j = 0; j < b[0].size(); j++) {
			for (ll k = 0; k < b.size(); k++) {
				ans[i][j] += a[i][k] * b[k][j];
				ans[i][j] %= mod;
			}
		}
	}

	return ans;
}

matrix go(matrix& a, ll b) {
	matrix ans;
	ans.assign(a.size(), vector<ll>(a.size(), 0));
	if (b == 0) {
		for (ll i = 0; i < ans.size(); i++)
			ans[i][i] = 1;
		return ans;
	}
	if (b == 1)
		return a;
	matrix tem = func(a, a);
	if (b % 2 == 0) {
		return go(tem, b / 2);
	}
	else {
		matrix temtem = go(tem, b / 2);
		return func(temtem, a);
	}
}

ll n, l, m;

ll kk[1000100];

int main() {
	scanf("%lld%lld%lld", &n, &l, &m);

	matrix a;
	a.assign(1, vector<ll>(m, 0));

	for (ll i = 0; i < n; i++) {
		ll tem;
		scanf("%lld", &tem);
		a[0][tem % m] ++;
	}

	matrix b;
	b.assign(m, vector<ll>(m, 0));

	ll xx[100] = { 0 ,};

	for (ll i = 0; i < n; i++) {
		scanf("%lld", &kk[i]);
		xx[kk[i] % m] ++;
	}

	for (ll i = 0; i < m; i++) {
		for (ll j = 0; j < m; j++) {
			b[i][j] += xx[(j - i + m) % m];
			b[i][j] %= mod;
		}
	}

	matrix mat = go(b, l - 2);

	matrix matmat;
	matmat.assign(m, vector<ll>(m, 0));

	ll c[100] = { 0, };
	for (ll i = 0; i < n; i++) {
		ll tem;
		scanf("%lld", &tem);
		c[(tem + kk[i])%m]++;
	}

	for (ll i = 0; i < m; i++) {
		matmat[i][0] = c[(m - i) % m];
	}
	matrix xxxxx = func(mat, matmat);
	matrix ans = func(a, xxxxx);

	printf("%lld", ans[0][0]);
}


#include<cstdio>
#include<cstring>
#include <algorithm>
typedef long long ll;

ll n, l, m;

ll a[100];
const ll mod = 1000000007;
ll b[100];
ll c[100];
ll d[100];
ll aa[100];

int main() {
	scanf("%lld%lld%lld", &n, &l, &m);

	for (ll i = 0; i < n; i++) {
		ll tmp;
		scanf("%lld", &tmp);
		a[tmp % m]++;
	}

	for (ll i = 0; i < n; i++) {
		scanf("%lld", &b[i]);
	}

	for (ll i = 0; i < n; i++) {
		ll tmp;
		scanf("%lld", &tmp);
		c[(tmp + b[i]) % m]++;
	}

	for (ll i = 0; i < n; i++) {
		d[b[i] % m]++;
	}

	for (ll i = 0; i < l - 2; i++) {
		for (ll j = 0; j < m; j++) {
			for (ll k = 0; k < m; k++) {
				aa[j] += a[k] * d[(j-k + m) % m];
				aa[j] %= mod;
			}
		}

		for (ll j = 0; j < m; j++) {
			a[j] = aa[j];
		}
		memset(aa, 0, sizeof(aa));
	}

	for (ll j = 0; j < m; j++) {
		for (ll k = 0; k < m; k++) {
			aa[j] += a[k] * c[(j - k + m) % m];
			aa[j] %= mod;
		}
	}

	printf("%lld", aa[0]);

}


#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
typedef long long LL;
const LL mod = 1e9 + 7;

const int maxn = 105;
struct Matrix
{
    LL m[maxn][maxn];
    Matrix(){memset(m, 0, sizeof(m));}
    void E(){memset(m, 0, sizeof(m)); for(int i = 0; i < maxn; i++) m[i][i] = 1;}
};

Matrix M_mul(Matrix a, Matrix b)
{
    Matrix ret;
    for(int i = 0; i < maxn; i++)
        for(int j = 0; j < maxn; j++)
            for(int k = 0; k < maxn; k++)
                ret.m[i][j] = ( ret.m[i][j] + (a.m[i][k] * b.m[k][j]) % mod ) % mod;
    return ret;
}

Matrix M_qpow(Matrix P, LL n)
{
    Matrix ret;
    ret.E();
    while(n)
    {
        if(n & 1LL) ret = M_mul(ret, P);
        n >>= 1LL;
        P = M_mul(P, P);
    }
    return ret;
}

LL a[1111111], b[1111111], c[1111111];
LL A[111], B[111], C[111];
int main(void)
{
    int N, L, M;
    scanf("%d %d %d", &N, &L, &M);
    for(int i = 1; i <= N; i++) scanf("%I64d", a + i);
    for(int i = 1; i <= N; i++) scanf("%I64d", b + i);
    for(int i = 1; i <= N; i++) scanf("%I64d", c + i);

    for(int i = 1; i <= N; i++) A[a[i]%M]++, B[b[i]%M]++;

    Matrix P;
    for(int i = 0; i < M; i++)
        for(int j = 0; j < M; j++)
            P.m[(i+j)%M][i] = (P.m[(i+j)%M][i] + B[j]) % mod;

    P = M_qpow(P, L - 2);

    for(int i = 0; i < M; i++)
        for(int j = 0; j < M; j++)
            C[i] = (C[i] + P.m[i][j] * A[j]) % mod;

    LL ans = 0;
    for(int i = 1; i <= N; i++) ans = (ans + C[(M+M-b[i]-c[i])%M]) % mod;
    printf("%I64d\n", ans);
    return 0;
}


#include <bits/stdc++.h>
#define L long long
#define ll long long
#define SS string
#define PB push_back
#define pp pair<L,L>
#define f(x, n , i) for (i = x ; i <= n ; i++)
#define setE(a, x , size) memset(a,x,size);
#define N 100500
#define INFY 1000000000000000000
#define EMPTY ""
#define mapss map<pair<L,L>,SS>
#define mapsi map<pair<L,L>,L>
#define reverse(s) reverse(s.begin(),s.end())
#define fr (s , e , i) for (i = s ; i >= e ; i--)
#define slen(s) s.length()
#define isEven(x) ((x%2)==0)
using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    ll A[a+b+c+d+1];
    ll n = a+b+c+d;
    ll turn, i = 0;
    turn = 0;
    ll p = a, q = b, r = c, s = d;
    while (a > 0 || b > 0)
    {
        if (turn == 0)
        {
            if (!a)
            break;
            turn = 1;
            A[i] = 0;
            a--;
            i++;
        }
        else
        {
            if (!b)
            break;
            turn = 0;
            A[i] = 1;
            b--;
            i++;
        }

    }
    if (b)
    {
        while (b > 0 || c > 0)
        {
        if (turn == 1)
        {
            if (!b)
            break;
            turn = 2;
            A[i] = 1;
            b--;
            i++;
        }
        else
        {
            if (!c)
            break;
            turn = 1;
            A[i] = 2;
            c--;
            i++;
        }

        }
    }
    else
    {
        if (turn = 0)
        turn = 2;
        else
        {
            if (c >= d)
            turn = 2;
            else
            turn = 3;
        }
    }

    while (c > 0 || d > 0)
    {

        if (turn == 2)
        {
            if (!c)
            break;
            turn = 3;
            A[i] = 2;
            c--;
            i++;
        }
        else
        {
            if (!d)
            break;
            turn = 2;
            A[i] = 3;
            d--;
            i++;
        }
    }
    while(a>0)
    {
        A[i] = 0;
        i++;
        a--;
    }
    while(b>0)
    {
        A[i] = 1;
        i++;
        b--;
    }
    while(c>0)
    {
        A[i] = 2;
        i++;
        c--;
    }
    while(d>0)
    {
        A[i] = 3;
        i++;
        d--;
    }
    ll j;
    // cout << A[0] << " ";
    f (1,n-1,j)
    {
        if (abs(A[j] - A[j-1]) != 1)
        break;
    }
    if (j == n)
    {

        cout << "YES\n";
        f(0,n-1,j)
        cout << A[j] << " ";
        return 0;
    }

    a = p;
    b = q;
    c = r;
    d = s;
    turn = 1;
    i = 0;
    while (a > 0 || b > 0)
    {
        if (turn == 0)
        {
            if (!a)
            break;
            turn = 1;
            A[i] = 0;
            a--;
            i++;
        }
        else
        {
            if (!b)
            break;
            turn = 0;
            A[i] = 1;
            b--;
            i++;
        }

    }
    if (b)
    {
        while (b > 0 || c > 0)
        {
        if (turn == 1)
        {
            if (!b)
            break;
            turn = 2;
            A[i] = 1;
            b--;
            i++;
        }
        else
        {
            if (!c)
            break;
            turn = 1;
            A[i] = 2;
            c--;
            i++;
        }

        }
    }
    else
    {
        if (turn == 0)
        turn = 2;
        else
        {
            if (c >= d)
            turn = 2;
            else
            turn = 3;
        }
    }
    while (c > 0 || d > 0)
    {

        if (turn == 2)
        {
            if (!c)
            break;
            turn = 3;
            A[i] = 2;
            c--;
            i++;
        }
        else
        {
            if (!d)
            break;
            turn = 2;
            A[i] = 3;
            d--;
            i++;
        }
    }
    while(a>0)
    {
        A[i] = 0;
        i++;
        a--;
    }
    while(b>0)
    {
        A[i] = 1;
        i++;
        b--;
    }
    while(c>0)
    {
        A[i] = 2;
        i++;
        c--;
    }
    while(d>0)
    {
        A[i] = 3;
        i++;
        d--;
    }
    f (1,n-1,j)
    {
        // cout << A[j] << " ";
        if (abs(A[j] - A[j-1]) != 1)
        break;
    }
    if (j == n)
    {

        cout << "YES\n";
        f(0,n-1,j)
        cout << A[j] << " ";
        return 0;
    }
    cout << "NO";
     return 0;
}


/*
队列优化深搜。
*/
#include <bits/stdc++.h>
using namespace std;
#define inf 0x3f3f3f3f;
typedef long long ll;
const int maxn = 1e5+5;
inline int read()
{
	char ch = getchar();
	int p = 1,data = 0;
	while(ch < '0' || ch > '9')
	{
		if(ch == '-')
			p = -1;
		ch = getchar();
	}
	while(ch>='0' && ch <= '9')
	{
		data = (data<<3)+(data<<1)+ch-'0';
		ch = getchar();
	}
	return p*data;
}
int a[4];
int ans[maxn];
bool flag;
void dfs(int pre,int k)
{
	if(flag)
		return;
	if(a[0] == a[1] && a[1] == a[2] && a[2] == a[3] && a[0] == 0 && (!flag))
	{
		printf("YES\n");
		flag = 1;
		for(int i = 0; i < k; i++)
		{
			if(i != k-1)
				printf("%d ",ans[i]);
			else
				printf("%d",ans[i]);
		}
		return;
	}
	if(pre == 0)
	{
		if(a[1])
		{
			a[1]--;
			ans[k] = 1;
			dfs(1,k+1);
			a[1]++;
		}
		else
		{
			return;
		}
	}
	else if(pre == 1)
	{
		if(a[2] >= a[0])
		{
			a[2]--;
			ans[k] = 2;
			dfs(2,k+1);
			a[2]++;
		}
		else if(a[2] == 0 && a[0] == 0)
		{
			return;
		}
		else
		{
			a[0]--;
			ans[k] = 0;
			dfs(0,k+1);
			a[0]++;
		}
	}
	else if(pre == 2)
	{
		if(a[3] >= a[1])
		{
			a[3]--;
			ans[k] = 3;
			dfs(3,k+1);
			a[3]++;
		}
		else if(a[3] == 0 && a[1] == 0)
		{
			return;
		}
		else
		{
			a[1]--;
			ans[k] = 1;
			dfs(1,k+1);
			a[1]++;
		}
	}
	else if(pre == 3)
	{
		if(a[2])
		{
			a[2]--;
			ans[k] = 2;
			dfs(2,k+1);
		}
		else
			return;
	}
}
int main()
{
	a[0] = read(),a[1] = read(), a[2] = read(), a[3] = read();
	int max1 = max(a[0],a[1]);
	int max2 = max(a[2],a[3]);
	int maxx = max(max1,max2);
	for(int i = 0; i < 4; i++)
	{
		if(maxx == a[i])
		{
			ans[0] = i;
			a[i]--;
			dfs(i,1);
			break;
		}
	}
	if(!flag)
		printf("NO");
	return 0;
}


/*
队列优化深搜。
*/
#include <bits/stdc++.h>
using namespace std;
#define inf 0x3f3f3f3f;
typedef long long ll;
const int maxn = 1e5+5;
inline int read()
{
	char ch = getchar();
	int p = 1,data = 0;
	while(ch < '0' || ch > '9')
	{
		if(ch == '-')
			p = -1;
		ch = getchar();
	}
	while(ch>='0' && ch <= '9')
	{
		data = (data<<3)+(data<<1)+ch-'0';
		ch = getchar();
	}
	return p*data;
}
int a[4];
int ans[maxn];
bool flag;
void dfs(int pre,int k)
{
	if(flag)
		return;
	if(a[0] == a[1] && a[1] == a[2] && a[2] == a[3] && a[0] == 0 && (!flag))
	{
		printf("YES\n");
		flag = 1;
		for(int i = 0; i < k; i++)
		{
			if(i != k-1)
				printf("%d ",ans[i]);
			else
				printf("%d",ans[i]);
		}
		return;
	}
	if(pre == 0)
	{
		if(a[1])
		{
			a[1]--;
			ans[k] = 1;
			dfs(1,k+1);
			a[1]++;
		}
		else
		{
			return;
		}
	}
	else if(pre == 1)
	{
		if(a[0])
		{
			a[0]--;
			ans[k] = 0;
			dfs(0,k+1);
		}
		else if(a[2])
		{
			a[2]--;
			ans[k] = 2;
			dfs(2,k+1);
		}
		else
			return;
	}
	else if(pre == 2)
	{
		if(a[3])
		{
			a[3]--;
			ans[k] = 3;
			dfs(3,k+1);
			a[3]++;
		}
		else if(a[1])
		{
			a[1]--;
			ans[k] = 1;
			dfs(1,k+1);
			a[1]++;
		}
		else
			return;
	}
	else if(pre == 3)
	{
		if(a[2])
		{
			a[2]--;
			ans[k] = 2;
			dfs(2,k+1);
		}
		else
			return;
	}
}
int main()
{
	a[0] = read(),a[1] = read(), a[2] = read(), a[3] = read();
	int max1 = max(a[0],a[1]);
	int max2 = max(a[2],a[3]);
	int maxx = max(max1,max2);
	if(a[0] == maxx)
	{
		ans[0] = 0;
		a[0]--;
		dfs(0,1);
	}
	else if(a[1] == maxx)
	{
		ans[0] = 1;
		a[1]--;
		dfs(1,1);
	}
	else if(a[3] == maxx)
	{
		ans[0] = 3;
		a[3]--;
		dfs(3,1);
	}
	else
	{
		ans[0] = 2;
		a[2]--;
		dfs(2,1);
	}
	if(!flag)
		printf("NO");
	return 0;
}


#include <bits/stdc++.h>
#define int long long

using namespace std;

const int O = 1e6 + 5;

int a, b, c, d;

deque <int> ans;

main(){
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    cin >> a >> b >> c >> d;
    if (a && b && c || a && b && c || a && c && d || b && c && d){
        for (int i = 1; i <= min(a, b); ++ i){
            ans.push_back(0);
            ans.push_back(1);
        }
        int cur = min(a, b);
        a -= cur; b -= cur;
        if (b == 1){
            -- b; ans.push_front(1);
        }
        for (int i = 1; i <= 2 * min(c, b); ++ i){
            ans.push_back(2);
            ans.push_back(1);
        }
        cur = min(b, c);
        b -= cur; c -= cur;
        if (b){
            -- b;
            ans.push_front(1);
        }
        for (int i = 1; i <= min(c, d); ++ i){
            ans.push_back(2);
            ans.push_back(3);
        }
        cur = min(c, d);
        c -= cur; d -= cur;
        if (c){
            -- c; ans.push_back(2);
        }
    }
    else{
    if (a && b && c == 0 && d == 0){
        for (int i = 1; i <= min(a, b); ++ i){
            ans.push_back(0);
            ans.push_back(1);
        }
        a -= min(a, b); b -= min(a, b);
        if (a){
            -- a;
            ans.push_back(0);
        }
        if (b){
            -- b;
            ans.push_front(1);
        }
    }
    if (c && d && a == 0 && b == 0){
        swap(a, c); swap(b, d);
        for (int i = 1; i <= min(a, b); ++ i){
            ans.push_back(2);
            ans.push_back(3);
        }
        a -= min(a, b); b -= min(a, b);
        if (a){
            -- a;
            ans.push_back(2);
        }
        if (b){
            -- b;
            ans.push_front(3);
        }
    }
    }
    if (a == 0 && b == 0 && c == 0 && d == 0){
        cout << "YES\n";
        while (ans.size()){
            cout << ans.front() << " ";
            ans.pop_front();
        }
        return 0;
    }
    cout << "NO";
}


#include <bits/stdc++.h>
#define int long long

using namespace std;

const int O = 1e6 + 5;

int a, b, c, d;

deque <int> ans;

main(){
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    cin >> a >> b >> c >> d;
    if (a && b && c || a && b && c || a && c && d || b && c && d){
        for (int i = 1; i <= min(a, b); ++ i){
            ans.push_back(0);
            ans.push_back(1);
        }
        int cur = min(a, b);
        a -= cur; b -= cur;
        for (int i = 1; i <= min(c, d); ++ i){
            ans.push_back(2);
            ans.push_back(3);
        }
        cur = min(c, d);
        c -= cur; d -= cur;
        for (int i = 1; i <= min(b, c); ++ i){
            ans.push_back(2);
            ans.push_back(1);
        }
        cur = min(b, c);
        b -= cur; c -= cur;
        if (b){
            ans.push_front(1);
            -- b;
        }
        if (c){
            ans.push_back(2); -- c;
        }
    }
    else{
    if (a && b && c == 0 && d == 0){
        for (int i = 1; i <= min(a, b); ++ i){
            ans.push_back(0);
            ans.push_back(1);
        }
        a -= min(a, b); b -= min(a, b);
        if (a){
            -- a;
            ans.push_back(0);
        }
        if (b){
            -- b;
            ans.push_front(1);
        }
    }
    if (c && d && a == 0 && b == 0){
        swap(a, c); swap(b, d);
        for (int i = 1; i <= min(a, b); ++ i){
            ans.push_back(2);
            ans.push_back(3);
        }
        a -= min(a, b); b -= min(a, b);
        if (a){
            -- a;
            ans.push_back(2);
        }
        if (b){
            -- b;
            ans.push_front(3);
        }
    }
    }
    if (a == 0 && b == 0 && c == 0 && d == 0){
        cout << "YES\n";
        while (ans.size()){
            cout << ans.front() << " ";
            ans.pop_front();
        }
        return 0;
    }
    cout << "NO";
}


#include <bits/stdc++.h>
#define int long long

using namespace std;

const int O = 1e6 + 5;

int a, b, c, d, ans[O], id;

bool flag = false;

main(){
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    cin >> a >> b >> c >> d;
    if (a && b && c && d){
        if (b > a){
            -- b;
            ++ id;
            ans[id] = 1;
        }
        int turn = 0;
        for (int i = id + 1; i <= id + min(a, b) * 2; ++ i){
            ans[i] = turn;
            turn ^= 1;
        }
        int cur = min(a, b);
        a -= cur; b -= cur;
        id += cur * 2;
        turn = 0;
        for (int i = id + 1; i <= id + 2 * min(b, c); ++ i){
            ans[i] = (turn == 0) ? (2) : (1);
            turn ^= 1;
        }
        cur = min(b, c);
        b -= cur; c -= cur;
        id += 2 * cur;
        turn = 0;
        /*if (c){
            -- c; ++ id;
            ans[id] = 2;
        }*/
        for (int i = id + 1; i <= id + 2 * min(c, d); ++ i){
            ans[i] = (turn == 0) ? (3) : (2);
            turn ^= 1;
        }
        cur = min(c, d);
        c -= cur; d -= cur;
        id += 2 * cur;
        if (c){
            -- c; ++ id;
            ans[id] = 2;
        }
        if (b){
            -- b; ++ id;
            ans[id] = 1;
        }
    }
    else{
        if (a && b){
            if (a > b){
                for (int i = 1; i <= b; ++ i){
                    ans[i] = (i & 1) ^ 1;
                    ++ id;
                }
                a -= b; b = 0;
                -- a; ++ id;
                ans[id] = 0;
            }
            else{
                for (int i = 1; i <= a; ++ i){
                    ans[i] = (i & 1) ^ 1 ^ 1;
                    ++ id;
                }
                a = 0; b -= a;
                if (b){
                    -- b; ++ id;
                    ans[id] = 1;
                }
            }
        }
        else{
            a = c; b = d;
            if (a > b){
                for (int i = 1; i <= b; ++ i){
                    ans[i] = (i & 1) ^ 1;
                    ++ id;
                }
                a -= b; b = 0;
                -- a; ++ id;
                ans[id] = 0;
            }
            else{
                for (int i = 1; i <= a; ++ i){
                    ans[i] = (i & 1) ^ 1 ^ 1;
                    ++ id;
                }
                a = 0; b -= a;
                if (b){
                    -- b; ++ id;
                    ans[id] = 1;
                }
            }
            for (int i = 1; i <= id; ++ i) ans[i] += 2;
        }
    }
    if (a == 0 && b == 0 && c == 0 && d == 0){
        cout << "YES\n";
        for (int i = 1; i <= id; ++ i) cout << ans[i] << " ";
        return 0;
    }
    cout << "NO";
}


#include <bits/stdc++.h>
#define int long long

using namespace std;

const int O = 1e6 + 5;

int a, b, c, d;

deque <int> ans;

main(){
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    cin >> a >> b >> c >> d;
    if (a && b && c || a && b && c || a && c && d || b && c && d){
        for (int i = 1; i <= min(a, b); ++ i){
            ans.push_back(0);
            ans.push_back(1);
        }
        int cur = min(a, b);
        a -= cur; b -= cur;
        for (int i = 1; i <= min(c, d); ++ i){
            ans.push_back(2);
            ans.push_back(3);
        }
        cur = min(c, d);
        c -= cur; d -= cur;
        for (int i = 1; i <= min(b, c); ++ i){
            ans.push_back(2);
            ans.push_back(1);
        }
        cur = min(b, c);
        b -= cur; c -= cur;
        if (b){
            ans.push_front(1);
            -- b;
        }
        if (c){
            ans.push_back(2); -- c;
        }
    }
    else{
    if (a && b && c == 0 && d == 0){
        for (int i = 1; i <= min(a, b); ++ i){
            ans.push_back(0);
            ans.push_back(1);
        }
        int cur = min(a, b);
        a -= cur; b -= cur;
        if (a){
            -- a;
            ans.push_back(0);
        }
        if (b){
            -- b;
            ans.push_front(1);
        }
    }
    if (c && d && a == 0 && b == 0){
        swap(a, c); swap(b, d);
        for (int i = 1; i <= min(a, b); ++ i){
            ans.push_back(2);
            ans.push_back(3);
        }
        int cur = min(a, b);
        a -= cur; b -= cur;
        if (a){
            -- a;
            ans.push_back(2);
        }
        if (b){
            -- b;
            ans.push_front(3);
        }
    }
    }
    if (a == 0 && b == 0 && c == 0 && d == 0){
        cout << "YES\n";
        while (ans.size()){
            cout << ans.front() << " ";
            ans.pop_front();
        }
        return 0;
    }
    cout << "NO";
}


#include <bits/stdc++.h>
#define int long long

using namespace std;

const int O = 1e6 + 5;

int a, b, c, d;

deque <int> ans;

main(){
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    cin >> a >> b >> c >> d;
    if (a == 1 && !b && !c && !d){
        cout << "YES\n0";
        return 0;
    }
    if (c == 1 && !b && !a && !d){
        cout << "YES\n2";
        return 0;
    }
    if (b == 1 && !a && !c && !d){
        cout << "YES\n1";
        return 0;
    }
    if (d == 1 && !b && !c && !a){
        cout << "YES\n3";
        return 0;
    }
    if (a && b && c || a && b && c || a && c && d || b && c && d || b && c){
        for (int i = 1; i <= min(a, b); ++ i){
            ans.push_back(0);
            ans.push_back(1);
        }
        int cur = min(a, b);
        a -= cur; b -= cur;
        for (int i = 1; i <= min(c, d); ++ i){
            ans.push_back(2);
            ans.push_back(3);
        }
        cur = min(c, d);
        c -= cur; d -= cur;
        for (int i = 1; i <= min(b, c); ++ i){
            ans.push_back(2);
            ans.push_back(1);
        }
        cur = min(b, c);
        b -= cur; c -= cur;
        if (b){
            ans.push_front(1);
            -- b;
        }
        if (c){
            ans.push_back(2); -- c;
        }
    }
    else{
    if (a && b && c == 0 && d == 0){
        for (int i = 1; i <= min(a, b); ++ i){
            ans.push_back(0);
            ans.push_back(1);
        }
        int cur = min(a, b);
        a -= cur; b -= cur;
        if (a){
            -- a;
            ans.push_back(0);
        }
        if (b){
            -- b;
            ans.push_front(1);
        }
    }
    if (c && d && a == 0 && b == 0){
        swap(a, c); swap(b, d);
        for (int i = 1; i <= min(a, b); ++ i){
            ans.push_back(2);
            ans.push_back(3);
        }
        int cur = min(a, b);
        a -= cur; b -= cur;
        if (a){
            -- a;
            ans.push_back(2);
        }
        if (b){
            -- b;
            ans.push_front(3);
        }
    }
    }
    if (a == 0 && b == 0 && c == 0 && d == 0){
        cout << "YES\n";
        while (ans.size()){
            cout << ans.front() << " ";
            ans.pop_front();
        }
        return 0;
    }
    cout << "NO";
}


#include <bits/stdc++.h>
#define int long long

using namespace std;

const int O = 1e6 + 5;

int a, b, c, d, ans[O], id;

bool flag = false;

main(){
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    cin >> a >> b >> c >> d;
    if (a && b && c && d){
        if (b > a){
            -- b;
            ++ id;
            ans[id] = 1;
        }
        int turn = 0;
        for (int i = id + 1; i <= id + min(a, b) * 2; ++ i){
            ans[i] = turn;
            turn ^= 1;
        }
        int cur = min(a, b);
        a -= cur; b -= cur;
        id += cur * 2;
        turn = 0;
        for (int i = id + 1; i <= id + 2 * min(b, c); ++ i){
            ans[i] = (turn == 0) ? (2) : (1);
            turn ^= 1;
        }
        cur = min(b, c);
        b -= cur; c -= cur;
        id += 2 * cur;
        turn = 0;
        if (c){
            -- c; ++ id;
            ans[id] = 2;
        }
        for (int i = id + 1; i <= id + 2 * min(c, d); ++ i){
            ans[i] = (turn == 0) ? (3) : (2);
            turn ^= 1;
        }
        cur = min(c, d);
        c -= cur; d -= cur;
        id += 2 * cur;
        if (c){
            -- c; ++ id;
            ans[id] = 2;
        }
        if (b){
            -- b; ++ id;
            ans[id] = 1;
        }
    }
    else{
        if (a && b){
            if (a > b){
                for (int i = 1; i <= b; ++ i){
                    ans[i] = (i & 1) ^ 1;
                    ++ id;
                }
                a -= b; b = 0;
                -- a; ++ id;
                ans[id] = 0;
            }
            else{
                for (int i = 1; i <= a; ++ i){
                    ans[i] = (i & 1) ^ 1 ^ 1;
                    ++ id;
                }
                a = 0; b -= a;
                if (b){
                    -- b; ++ id;
                    ans[id] = 1;
                }
            }
        }
        else{
            a = c; b = d;
            if (a > b){
                for (int i = 1; i <= b; ++ i){
                    ans[i] = (i & 1) ^ 1;
                    ++ id;
                }
                a -= b; b = 0;
                -- a; ++ id;
                ans[id] = 0;
            }
            else{
                for (int i = 1; i <= a; ++ i){
                    ans[i] = (i & 1) ^ 1 ^ 1;
                    ++ id;
                }
                a = 0; b -= a;
                if (b){
                    -- b; ++ id;
                    ans[id] = 1;
                }
            }
            for (int i = 1; i <= id; ++ i) ans[i] += 2;
        }
    }
    if (a == 0 && b == 0 && c == 0 && d == 0){
        cout << "YES\n";
        for (int i = 1; i <= id; ++ i) cout << ans[i] << " ";
        return 0;
    }
    cout << "NO";
}


#include <bits/stdc++.h>
#define int long long

using namespace std;

const int O = 1e6 + 5;

int a, b, c, d, ans[O], id;

bool flag = false;

main(){
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    cin >> a >> b >> c >> d;
    if (a && b && c && d){
        if (b > a){
            -- b;
            ++ id;
            ans[id] = 1;
        }
        int turn = 0;
        for (int i = id + 1; i <= id + min(a, b) * 2; ++ i){
            ans[i] = turn;
            turn ^= 1;
        }
        int cur = min(a, b);
        a -= cur; b -= cur;
        id += cur * 2;
        turn = 0;
        for (int i = id + 1; i <= id + 2 * min(b, c); ++ i){
            ans[i] = (turn == 0) ? (2) : (1);
            turn ^= 1;
        }
        cur = min(b, c);
        b -= cur; c -= cur;
        id += 2 * cur;
        turn = 0;
        /*if (c){
            -- c; ++ id;
            ans[id] = 2;
        }*/
        for (int i = id + 1; i <= id + 2 * min(c, d); ++ i){
            ans[i] = (turn == 0) ? (2) : (3);
            turn ^= 1;
        }
        cur = min(c, d);
        c -= cur; d -= cur;
        id += 2 * cur;
        if (c){
            -- c; ++ id;
            ans[id] = 2;
        }
        if (b){
            -- b; ++ id;
            ans[id] = 1;
        }
    }
    else{
        if (a && b){
            if (a > b){
                for (int i = 1; i <= b; ++ i){
                    ans[i] = (i & 1) ^ 1;
                    ++ id;
                }
                a -= b; b = 0;
                -- a; ++ id;
                ans[id] = 0;
            }
            else{
                for (int i = 1; i <= a; ++ i){
                    ans[i] = (i & 1) ^ 1 ^ 1;
                    ++ id;
                }
                a = 0; b -= a;
                if (b){
                    -- b; ++ id;
                    ans[id] = 1;
                }
            }
        }
        else{
            a = c; b = d;
            if (a > b){
                for (int i = 1; i <= b; ++ i){
                    ans[i] = (i & 1) ^ 1;
                    ++ id;
                }
                a -= b; b = 0;
                -- a; ++ id;
                ans[id] = 0;
            }
            else{
                for (int i = 1; i <= a; ++ i){
                    ans[i] = (i & 1) ^ 1 ^ 1;
                    ++ id;
                }
                a = 0; b -= a;
                if (b){
                    -- b; ++ id;
                    ans[id] = 1;
                }
            }
            for (int i = 1; i <= id; ++ i) ans[i] += 2;
        }
    }
    if (a == 0 && b == 0 && c == 0 && d == 0){
        cout << "YES\n";
        for (int i = 1; i <= id; ++ i) cout << ans[i] << " ";
        return 0;
    }
    cout << "NO";
}


#include <bits/stdc++.h>
#define int long long

using namespace std;

const int O = 1e6 + 5;

int a, b, c, d;

deque <int> ans;

main(){
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    cin >> a >> b >> c >> d;
    if (a == 1 && !b && !c && !d){
        cout << "YES\n0";
        return 0;
    }
    if (c == 1 && !b && !a && !d){
        cout << "YES\n2";
        return 0;
    }
    if (b == 1 && !a && !c && !d){
        cout << "YES\n1";
        return 0;
    }
    if (d == 1 && !b && !c && !a){
        cout << "YES\n3";
        return 0;
    }
    if (a && b && c || a && b && c || a && c && d || b && c && d){
        for (int i = 1; i <= min(a, b); ++ i){
            ans.push_back(0);
            ans.push_back(1);
        }
        int cur = min(a, b);
        a -= cur; b -= cur;
        for (int i = 1; i <= min(c, d); ++ i){
            ans.push_back(2);
            ans.push_back(3);
        }
        cur = min(c, d);
        c -= cur; d -= cur;
        for (int i = 1; i <= min(b, c); ++ i){
            ans.push_back(2);
            ans.push_back(1);
        }
        cur = min(b, c);
        b -= cur; c -= cur;
        if (b){
            ans.push_front(1);
            -- b;
        }
        if (c){
            ans.push_back(2); -- c;
        }
    }
    else{
    if (a && b && c == 0 && d == 0){
        for (int i = 1; i <= min(a, b); ++ i){
            ans.push_back(0);
            ans.push_back(1);
        }
        int cur = min(a, b);
        a -= cur; b -= cur;
        if (a){
            -- a;
            ans.push_back(0);
        }
        if (b){
            -- b;
            ans.push_front(1);
        }
    }
    if (c && d && a == 0 && b == 0){
        swap(a, c); swap(b, d);
        for (int i = 1; i <= min(a, b); ++ i){
            ans.push_back(2);
            ans.push_back(3);
        }
        int cur = min(a, b);
        a -= cur; b -= cur;
        if (a){
            -- a;
            ans.push_back(2);
        }
        if (b){
            -- b;
            ans.push_front(3);
        }
    }
    }
    if (a == 0 && b == 0 && c == 0 && d == 0){
        cout << "YES\n";
        while (ans.size()){
            cout << ans.front() << " ";
            ans.pop_front();
        }
        return 0;
    }
    cout << "NO";
}