#include #include #include #include using namespace std; using ll = long long; using vi = vector; #define in(v) v; cin >> v; #define rep(i,n) for(int i=0;i<(n);++i) int main() { int in(N); int in(M); ll in(K); char in(op); vi A(N), B(M); rep(i, M) cin >> B[i]; rep(i, N) cin >> A[i]; if (op == '+') { map count; ll ans = 0; rep(i, M) ++count[B[i] % K]; rep(i, N) ans += count[(K - (A[i] % K)) % K]; cout << ans << endl; } else { map count, count2; rep(i, M) ++count[gcd(B[i], K)]; rep(i, N) ++count2[gcd(A[i], K)]; ll ans = 0; for (const auto& [a, e] : count2) { ll tmp = 0; for (int j = 1; j * j <= a; ++j) { if (a % j == 0) { tmp += count[K / (a/j)]; if (a != j * j) tmp += count[K / j]; } } ans += tmp * e; } cout << ans << endl; } return 0; }