#include #include #include #include #include using namespace std; using ll = long long; using vi = vector; #define rep(i,n) for(int i=0;i<(n);++i) #define all(f,c,...) (([&](decltype((c)) cccc) { return (f)(begin(cccc), end(cccc), ## __VA_ARGS__); })(c)) int main() { int N, M, K; cin >> N >> M >> K; char op; cin >> op; vi B(M); rep(i, M) cin >> B[i]; if (op == '+') { vi m(K, 0); rep(i, M) ++m[B[i] % K]; ll ans = 0; rep(i, N) { int A; cin >> A; ans += m[(K - A % K) % K]; } cout << ans << endl; } else { vi div; for (ll i = 1; i * i <= K; ++i) { if (K % i == 0) { div.push_back(i); if (i * i != K) div.push_back(K / i); } } map m; rep(i, M) { ++m[gcd(B[i], K)]; } all(sort, div); ll ans = 0; rep(i, N) { int A; cin >> A; for (const auto& e : div) { if (A % e == 0) { ans += m[K / e]; } } } cout << ans << endl; } return 0; }