#include "bits/stdc++.h" #define rep(i,n) for(int i=0;i> N >> M >> K >> op; vector A(N), B(M); rep(i, M) { cin >> B[i]; } rep(i, N) { cin >> A[i]; } map ma, mb; ll ans = 0; if (op == '+') { rep(i, N) ma[A[i] % K]++; rep(i, M) mb[B[i] % K]++; for (auto p : ma) { ans += p.second * mb[(K - p.first) % K]; } } else { rep(i, N) ma[A[i] / gcd(A[i], K)]++; rep(i, M) mb[gcd(B[i], K)]++; for (auto p : ma) { for (auto q : mb) { if ((p.first * q.first) % K == 0) ans += p.second * q.second; } } } cout << ans << endl; }