#include using namespace std; #define endl '\n' #define lfs cout<= (ll)(n); i--) using ll = long long; using ld = long double; const ll MOD = 1e9+7; //const ll MOD = 998244353; const ll INF = 1e18; using P = pair; template bool chmin(T &a,T b){if(a>b){a=b;return true;}else return false;} template bool chmax(T &a,T b){if(a void ans(bool x,T1 y,T2 z){if(x)cout< void debug(vector>&v,ll h,ll w){for(ll i=0;i&v,ll h,ll w){for(ll i=0;i void debug(vector&v,ll n){if(n!=0)cout< vector>vec(ll x, ll y, T w){ vector>v(x,vector(y,w));return v;} ll gcd(ll x,ll y){ll r;while(y!=0&&(r=x%y)!=0){x=y;y=r;}return y==0?x:y;} vectordx={1,0,-1,0,1,1,-1,-1}; vectordy={0,1,0,-1,1,-1,1,-1}; template vector make_v(size_t a,T b){return vector(a,b);} template auto make_v(size_t a,Ts... ts){ return vector(a,make_v(ts...)); } ostream &operator<<(ostream &os, pair&p){ return os << p.first << " " << p.second; } map factoring(ll n){ ll buf=n; mapret; ll i,j; for(i=2;buf!=1&&i*i<=n;i++){ for(j=0;buf%i==0;j++){ buf/=i; } if(j>0)ret.emplace(i,j); } if(buf!=1)ret.emplace(buf,1); return ret; } vectordivisor(ll n){ vectorret; for(ll i=1;i*i<=n;i++){ if(n%i==0&&i*i!=n){ ret.PB(i); ret.PB(n/i); } else if(n%i==0) ret.PB(i); } sort(ALL(ret)); return ret; } int main(){ cin.tie(nullptr); ios_base::sync_with_stdio(false); ll res=0,buf=0; bool judge = true; ll n,m,k;cin>>n>>m>>k; char c;cin>>c; vectorb(m); rep(i,0,m)cin>>b[i]; vectora(n); rep(i,0,n)cin>>a[i]; if(c=='+'){ mapmpa; mapmpb; rep(i,0,n)mpa[a[i]%k]++; rep(i,0,m)mpb[b[i]%k]++; for(auto z:mpa){ if(z.fi!=0)res+=z.se*mpb[k-z.fi]; else res+=z.se*mpb[0]; } } else{ auto mp=factoring(k); auto div=divisor(k); mapidx; rep(i,0,div.size())idx[div[i]]=i; ll sz=div.size(); vectorcnt(sz); mapmpa; rep(i,0,n)mpa[gcd(a[i],k)]++; rep(i,0,m)cnt[idx[gcd(b[i],k)]]++; for(auto z:mp){ rrep(i,0,sz){ if(div[i]%z.fi==0)cnt[idx[div[i]/z.fi]]+=cnt[i]; } } //debug(cnt,sz); //debug(div,sz); for(auto z:mpa){ ll need=k/z.fi; res+=cnt[idx[need]]*z.se; } } cout<