#include using namespace std; using ll = long long; using ul = unsigned long; using ull = unsigned long long; template T gcd(T a, T b) { return b == 0 ? a : gcd(b, a % b); } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); ll n, m, k; cin >> n >> m >> k; string op; cin >> op; vector b(m); for (auto&& it : b) cin >> it; ll res{ 0 }; if (op == "+") { map mb; for (auto&& it : b) ++mb[it % k]; for (int i = 0; i < n; ++i) { ll a; cin >> a; ll mod = -a % k; if (mod < 0) mod += k; if (mb.count(mod)) res += mb[mod]; } } else { map gcdb, gcda; for (auto&& it : b) ++gcdb[gcd(it, k)]; for (int i = 0; i < n; ++i) { ll a; cin >> a; ++gcda[gcd(a, k)]; } for (const auto& itb : gcdb) for (const auto& ita : gcda) if ((ita.first * itb.first) % k == 0) res += ita.second * itb.second; } cout << res << "\n"; return 0; }