#include std::vector divisor_list(std::int64_t n){ std::vector temp, ret; { std::int64_t i; for(i = 1LL; i*i < n; ++i){ if(n%i == 0){ temp.push_back(n / i); ret.push_back(i); } } if(i*i == n) ret.push_back(i); } std::reverse(temp.begin(), temp.end()); ret.insert(ret.end(), temp.begin(), temp.end()); return ret; } int main(){ int N, M, K; std::cin >> N >> M >> K; char op; std::cin >> op; std::vector A(N), B(M); for(int i = 0; i < M; ++i) std::cin >> B[i]; for(int i = 0; i < N; ++i) std::cin >> A[i]; std::sort(A.begin(), A.end()); std::sort(B.begin(), B.end()); std::map count; for(auto x : B) count[x % K] += 1; auto divs = divisor_list(K); std::map count_div; for(auto x : B){ for(auto d : divs){ if(x % d == 0){ count_div[d] += 1; } } } int64_t ans = 0; if(op == '+'){ for(auto x : A){ if(x % K == 0){ ans += count[0]; }else{ ans += count[K - (x % K)]; } } }else{ for(auto x : A){ if(x % K == 0){ ans += M; }else{ int64_t t = K / (std::gcd(K, x)); ans += count_div[t]; } } } std::cout << ans << std::endl; return 0; }