#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()); vector C(divisor.size(), 0), D(divisor.size(), 0); for (const auto& e : A) { const int p = lower_bound(divisor.begin(), divisor.end(), gcd(e, K)) - divisor.begin(); C[p]++; } for (const auto& e : B) { const int p = lower_bound(divisor.begin(), divisor.end(), gcd(e, K)) - divisor.begin(); D[p]++; } 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; }