#define _USE_MATH_DEFINES #include using namespace std; signed main() { ios::sync_with_stdio(false); cin.tie(0); int n, m, k; cin >> n >> m >> k; char op; cin >> 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]; long long ans = 0; if (op == '+') { map mp; for (int i = 0; i < n; i++) mp[b[i] % k]++; for (int i = 0; i < n; i++) ans += mp[(k - a[i] % k) % k]; } else { map mp1, mp2; for (int i = 0; i < n; i++) mp1[__gcd(a[i], k)]++; for (int i = 0; i < m; i++) mp2[__gcd(b[i], k)]++; vector> v, w; for (auto p : mp1) v.push_back(p); for (auto p : mp2) w.push_back(p); for (auto& p : v) for (auto& q : w) if (1LL * p.first * q.first % k == 0) { ans += 1LL * p.second * q.second; } } cout << ans << endl; return 0; }