#include #include #include #include using lint = long long; void solve() { int n, m, k; char op; std::cin >> n >> m >> k >> op; if (op == '+') { std::map cnt; while (m--) { int x; std::cin >> x; x %= k; if (!cnt.count(x)) cnt[x] = 0; ++cnt[x]; } lint ans = 0; while (n--) { int x; std::cin >> x; x = (k - x % k) % k; if (cnt.count(x)) ans += cnt[x]; } std::cout << ans << "\n"; } else { std::map acnt, bcnt; while (m--) { int x; std::cin >> x; x = std::gcd(x, k); if (!bcnt.count(x)) bcnt[x] = 0; ++bcnt[x]; } while (n--) { int x; std::cin >> x; x = std::gcd(x, k); if (!acnt.count(x)) acnt[x] = 0; ++acnt[x]; } lint ans = 0; for (auto [p1, c1] : acnt) { for (auto [p2, c2] : bcnt) { if (p1 * p2 % k == 0) ans += c1 * c2; } } std::cout << ans << "\n"; } } int main() { std::cin.tie(nullptr); std::ios::sync_with_stdio(false); solve(); return 0; }