#include #include #include #include #define llint long long using namespace std; llint h, w, k; char op; int a[100005], b[100005]; vector vec; int num[2005]; map mp, mpA, mpB; int gcd(int a,int b) { if(b == 0) return a; return gcd(b, a%b); } int main(void) { ios::sync_with_stdio(0); cin.tie(0); cin >> h >> w >> k; cin >> op; for(int i = 1; i <= w; i++) cin >> a[i]; for(int i = 1; i <= h; i++) cin >> b[i]; for(int i = 1; i <= w; i++) mpA[a[i]%k]++; for(int i = 1; i <= h; i++) mpB[b[i]%k]++; if(op == '+'){ llint ans = 0; for(auto it = mpA.begin(); it != mpA.end(); it++){ ans += it->second * mpB[(k-it->first) % k]; } cout << ans << endl; return 0; } else{ for(int i = 1; i*i <= k; i++){ if(k % i == 0){ vec.push_back(i); vec.push_back(k/i); } } sort(vec.begin(), vec.end()); vec.erase(unique(vec.begin(), vec.end()), vec.end()); int m = vec.size(); for(int i = 0; i < m; i++) mp[vec[i]] = i; for(int i = 1; i <= w; i++){ for(int j = 0; j < m; j++){ if(a[i] % vec[j] == 0) num[j]++; } } llint ans = 0; for(int i = 1; i <= h; i++){ llint g = gcd(k, b[i]); ans += num[mp[k / g]]; } cout << ans << endl; return 0; } return 0; }