#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; using i64 = int64_t; using i32 = int32_t; i64 gcd(i64 x, i64 y) { while (y > 0) { x %= y; swap(x, y); } return x; } int main() { i64 n, m, k; char op; cin >> n >> m >> k >> op; vector a(n), b(m); for (int i = 0; i < m; ++i) cin >> b[i]; for (int i = 0; i < n; ++i) cin >> a[i]; i64 ans = 0; if (op == '+') { map ma, mb; for (i64 x : a) ma[x % k]++; for (i64 x : b) mb[x % k]++; for (auto p : ma) { i64 x, c; tie(x, c) = p; ans += c * mb[(k - x) % k]; } } else { map ma, mb; for (i64 x : a) ma[gcd(x, k)]++; for (i64 x : b) mb[gcd(x, k)]++; for (auto p : ma) { i64 x, c; tie(x, c) = p; for (auto p : mb) { i64 y, d; tie(y, d) = p; if (x * y % k == 0) { ans += c * d; } } } } cout << ans << endl; return 0; }