#include #include #include using namespace std; #define REP(i,m,n) for(int i=(m);i<(n);i++) #define rep(i,n) REP(i,0,n) #define pb push_back #define all(a) a.begin(),a.end() #define rall(c) (c).rbegin(),(c).rend() #define mp make_pair #define double long double typedef long long ll; typedef pair pii; typedef pair pll; typedef vector vec; typedef vector mat; const ll inf=1e9+7; const ll mod=1e9+7; //gcd ll gcd(ll a,ll b){ if(max(a,b)%min(a,b)==0)return min(a,b); return gcd(min(a,b),max(a,b)%min(a,b)); } int main(){ ll n,m,k;cin>>n>>m>>k; vectora(n),b(m); char c;cin>>c; bool f=c=='+'; rep(i,m)cin>>b[i]; rep(i,n)cin>>a[i]; if(f){ mapma; rep(i,m){ ll s=b[i]%k; if(s<0)s+=k; if(ma.find(s)!=ma.end())ma[s]++; else ma[s]=1; } ll ans=0; rep(i,n){ ll s=a[i]%k; if(s<=0)s+=k; if(ma.find(k-s)!=ma.end())ans=ans+ma[k-s]; } cout<ma,ma2; rep(i,n){ ll s=gcd(k,a[i]); if(ma.find(s)!=ma.end())ma[s]++; else ma[s]=1; } rep(i,m){ ll s=gcd(k,b[i]); if(ma2.find(s)!=ma2.end())ma2[s]++; else ma2[s]=1; } ll ans=0; for(auto e:ma){ for(auto g:ma2){ if(e.first*g.first%k==0)ans=ans+e.second*g.second; } } cout<