#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; typedef long long ll; typedef pair P; typedef pair Pid; typedef pair Pdi; typedef pair Pl; typedef pair> PP; const double PI = 3.1415926535897932; // acos(-1) const double EPS = 1e-15; const int INF = 1001001001; const int mod = 1e+9 + 7; #define chmax(x, y) x = max(x, y) #define chmin(x, y) x = min(x, y) #define chadd(x, y) x = (x + y) % mod ll modinv(ll a, ll m){ ll b = m, u = 1, v = 0; while(b){ ll t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); } u %= m; if(u < 0) u += m; return u; } int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); int n, m; ll k; char op; cin >> n >> m >> k >> op; vector b(m); vector a(n); ll res = 0; if(op == '+'){ for(int i = 0; i < m; ++i){ cin >> b[i]; b[i] %= k; } for(int i = 0; i < n; ++i){ cin >> a[i]; a[i] %= k; } sort(b.begin(), b.end()); for(int i = 0; i < n; ++i){ res += upper_bound(b.begin(), b.end(), k - a[i]) - lower_bound(b.begin(), b.end(), k - a[i]); } } else{ for(int i = 0; i < m; ++i) cin >> b[i]; for(int i = 0; i < n; ++i) cin >> a[i]; map gcd_a, gcd_b; for(int i = 0; i < n; ++i) ++gcd_a[__gcd(a[i], k)]; for(int i = 0; i < m; ++i) ++gcd_b[__gcd(b[i], k)]; for(auto A : gcd_a){ for(auto B : gcd_b){ if(A.first * B.first % k == 0) res += A.second * B.second; } } } cout << res << endl; }