#include int64_t calcGCD(int64_t a, int64_t b) { while (a) { b %= a; std::swap(a, b); } return b; } int main() { int N, M; int64_t K; char op; scanf("%d%d%lld %c", &N, &M, &K, &op); std::vector A(N), B(M); for (auto& e: B) scanf("%lld", &e); for (auto& e: A) scanf("%lld", &e); int64_t ans{}; if (op == '+') { std::map rest_a, rest_b; for (auto& e: A) rest_a[e % K]++; for (auto& e: B) rest_b[e % K]++; for (auto& e: rest_a) ans += e.second * rest_b[K - e.first]; ans += rest_a[0] * rest_b[0]; } else { std::map gcd_a, gcd_b; for (auto& e: A) gcd_a[calcGCD(e, K)]++; for (auto& e: B) gcd_b[calcGCD(e, K)]++; for (int64_t i{1}; i * i <= K; i++) if (K % i == 0) gcd_b[i] += 0; for (auto& e: gcd_b) for (int64_t i{2 * e.first}; i <= K; i += e.first) gcd_b[e.first] += gcd_b[i]; for (auto& e: gcd_a) ans += e.second * gcd_b[K / e.first]; } printf("%lld\n", ans); return 0; }