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

using ll=long long;

int gcd(int a,int b){
	return a?gcd(b%a,a):b;
}

int main(){cin.tie(0);ios::sync_with_stdio(false);
	int N,M,K;cin>>N>>M>>K;
	string op;cin>>op;
	ll z=0;
	if(op=="+"){
		map<int,int>m;
		for(int i=0;i<M;++i){
			int B;cin>>B;
			++m[B%K];
		}
		for(int i=0;i<N;++i){
			int A;cin>>A;
			z+=m[(K-A%K)%K];
		}
	}else{
		map<int,int>m;
		for(int i=0;i<M;++i){
			int B;cin>>B;
			++m[gcd(K,B)];
		}
		for(int i=0;i<N;++i){
			int A;cin>>A;
			for(auto b:m){
				if(A*b.first%K==0){
					z+=b.second;
				}
			}
		}
	}
	cout<<z<<"\n";
	return 0;
}