#include using namespace std; #define rep(i,n) for(int i=0;i bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;} typedef long long ll; const ll INF = 1e18; const ll MOD = 1e9+7; const ll MAX = 400005; long long fac[MAX], finv[MAX], inv[MAX]; ll modpow(ll a, ll n, ll mod=MOD) { ll res = 1; while (n > 0) { if (n & 1) res = res * a % mod; a = a * a % mod; n >>= 1; } return res; } ll modinv(ll a,ll m=MOD) { ll b=m,u=1,v=0; while(b){ ll t=a/b; a-=t*b; swap(a,b); u-=t*v; swap(u,v); } u%=m; if(u<0) u+=m; return u; } void COMinit(){ fac[0]=fac[1]=1; finv[0]=finv[1]=1; inv[1]=1; for (ll i=2;i division(ll n){ set S; ll num = 1; ll root = (ll)(sqrt(n)); while(num<=root){ if (n%num == 0){ S.insert(num); S.insert(n/num); } num++; } return S; } int main(){ ll H,W,K;cin >> H >> W >> K; set set = division(K); ll root = (ll)(sqrt(K)); string op;cin >> op; vector h(H),w(W); rep(i,W) cin >> w[i]; rep(i,H) cin >> h[i]; //sort(h.begin(),h.end()); //sort(w.begin(),w.end()); ll res = 0; if(op == "+"){ map hash,hasw; rep(i,H){ hash[h[i] % K] += 1; } rep(i,W){ hasw[w[i] % K] += 1; } rep(i,K){ res += hash[i % K] * hasw[(K-i) % K]; } }else{ map hash,hasw; rep1(i,root){ if(set.count(i)){ rep(j,H){ if(h[j] % i == 0) hash[i] += 1; if(h[j] % (K / i) == 0 && i != (K / i)) hash[K / i] += 1; } rep(j,W){ if(w[j] % i == 0) hasw[i] += 1; if(w[j] % (K / i) == 0 && i != (K / i)) hasw[K / i] += 1; } } } for(auto p : hash){ auto key = p.first; auto value = p.second; // cout << key << " "<< value << " " << K/key << " " << hasw[K /key] << endl; res += value * hasw[K / key]; } } cout << res << endl; }