#include using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n, m, k; cin >> n >> m >> k; char op; cin >> op; vector a(n), b(m), c(m); map mp1, mp2; for (int i = 0; i < m; ++i) { cin >> b[i]; ++mp2[b[i] % k]; c[i] = __gcd(b[i], k); } for (int i = 0; i < n; ++i) { cin >> a[i]; } long long ans = 0; if (op == '*') { for (int i = 0; i < m; ++i) { if (mp1[c[i]]) ans += mp1[c[i]]; else { for (int j = 0; j < n; ++j) { if (1LL * c[i] * a[j] % k == 0) ++mp1[c[i]]; } ans += mp1[c[i]]; } } } else { for (int i = 0; i < n; ++i) { ans += mp2[(k - a[i] % k) % k]; } } cout << ans << '\n'; return 0; }