#include #define REP(i,n) for(int i=0,i##_len=int(n);i>N>>M>>K; char op;cin>>op; vector A(N),B(M); REP(i,M) cin>>B[i]; REP(i,N) cin>>A[i]; ll ans=0; sort(All(B)); if(op=='+'){ map mp; REP(i,M) mp[B[i]%K]++; REP(i,N) ans+=mp[K-A[i]%K]; cout< d; for(ll i=1;i*i<=K;++i){ if(K%i==0){ d.push_back(i); if(i*i!=K){ d.push_back(K/i); } } } sort(All(d)); map imos; REP(i,M) for(int j=d.size()-1;j>=0;--j){ if(B[i]%d[j]==0){ imos[K/d[j]]++; break; } } REP(i,N) REP(j,d.size()){ if(A[i]%d[j]==0){ ans+=imos[d[j]]; } } cout<