#include using namespace std; int gcd(int a, int b){ if (b == 0){ return a; } else { return gcd(b, a % b); } } int main(){ int N, M, K; cin >> N >> M >> K; char op; cin >> op; vector B(M); for (int i = 0; i < M; i++){ cin >> B[i]; } vector A(N); for (int i = 0; i < N; i++){ cin >> A[i]; } if (op == '+'){ map cntA; for (int i = 0; i < N; i++){ cntA[A[i] % K]++; } map cntB; for (int i = 0; i < M; i++){ cntB[B[i] % K]++; } long long ans = 0; for (auto P : cntA){ ans += (long long) P.second * cntB[(K - P.first) % K]; } cout << ans << endl; } if (op == '*'){ vector F; for (int i = 1; i * i <= K; i++){ if (K % i == 0){ F.push_back(i); if (i * i < K){ F.push_back(K / i); } } } sort(F.begin(), F.end()); int c = F.size(); vector cntA(c, 0); for (int i = 0; i < N; i++){ int p = lower_bound(F.begin(), F.end(), gcd(K, A[i])) - F.begin(); cntA[p]++; } vector cntB(c, 0); for (int i = 0; i < M; i++){ int p = lower_bound(F.begin(), F.end(), gcd(K, B[i])) - F.begin(); cntB[p]++; } long long ans = 0; for (int i = 0; i < c; i++){ for (int j = 0; j < c; j++){ if ((long long) F[i] * F[j] % K == 0){ ans += (long long) cntA[i] * cntB[j]; } } } cout << ans << endl; } }