#include using namespace std; int gcd(int a, int b){ return b==0 ? a : gcd(b, a%b); } int main(){ int N, M, K; char op; cin >> N >> M >> K >> op; vector A(N), B(M); for(int i=0; i> B[i]; for(int i=0; i> A[i]; int64_t ans = 0; if(op == '+'){ map num; for(int b : B) num[b%K]++; for(int a : A) ans += num[(K-a%K)%K]; }else{ map mp; for(int i=1; i*i <= K; i++) if(K%i == 0){ mp[i] = mp[K/i] = 0; } int sz = 0; vector V; for(auto& p : mp){ V.push_back(p.first); p.second = sz++; } vector num(sz); for(int b : B) num[mp[gcd(K, b)]]++; for(int i=0; i