#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); for (auto&& e : B) { cin >> e; } for (auto&& e : A) { cin >> e; } if (op == '+') { map mp; for (const auto& e : A) { mp[e % K]++; } int64_t res = 0; for (const auto& e : B) { res += mp[(2 * K - (e % K)) % K]; } cout << res << '\n'; } else { vector divisor; for (int i = 1; i * i < K + 1; i++) { if (K % i == 0) { divisor.emplace_back(i); if (i * i != K) divisor.emplace_back(K / i); } } sort(divisor.begin(), divisor.end()); map index; for (int i = 0; i < (int)divisor.size(); i++) { index[divisor[i]] = i; } vector C(2000, 0), D(2000, 0); for (const auto& e : A) { if (index.find(gcd(e, K)) != index.end()) C[index[gcd(e, K)]]++; } for (const auto& e : B) { if (index.find(gcd(e, K)) != index.end()) D[index[gcd(e, K)]]++; } int64_t res = 0; for (int i = 0; i < (int)divisor.size(); i++) { for (int j = 0; j < (int)divisor.size(); j++) { if ((divisor[i] * divisor[j]) % K == 0) res += C[i] * D[j]; } } cout << res << '\n'; } return 0; }