#include using namespace std; //repetition #define FOR(i,a,b) for(ll i=(a);i<(b);++i) #define rep(i, n) for(ll i = 0; i < (ll)(n); i++) //container util #define all(x) (x).begin(),(x).end() //typedef typedef long long ll; typedef vector VI; typedef vector VVI; typedef vector VLL; typedef vector VVLL; typedef vector VS; typedef pair PII; typedef pair PLL; //const value //const ll MOD = 1e9 + 7; //const int dx[] = {0,1,0,-1};//{0,0,1,1,1,-1,-1,-1}; //const int dy[] = {1,0,-1,0};//{1,-1,0,1,-1,0,1,-1}; //conversion inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;} inline ll toLL(string s) {ll v; istringstream sin(s);sin>>v;return v;} template inline string toString(T x) {ostringstream sout;sout<=mod) x-=mod; return *this;} mint& operator-=(const mint& a){ if((x+=mod-a.x)>=mod) x-=mod; return *this;} mint& operator*=(const mint& a){ (x*=a.x)%=mod; return *this;} mint operator+(const mint& a)const{ return mint(*this) += a;} mint operator-(const mint& a)const{ return mint(*this) -= a;} mint operator*(const mint& a)const{ return mint(*this) *= a;} bool operator<(const mint& a)const{ return x < a.x;} bool operator==(const mint& a)const{ return x == a.x;} }; istream& operator>>(istream&i,mint&a){i>>a.x;return i;} ostream& operator<<(ostream&o,const mint&a){o< vm; typedef vector vvm; // ll modinv(long long a, long long m) { long long b = m, u = 1, v = 0; while (b) { long long t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); } u %= m; if (u < 0) u += m; return u; } long long gcd( long long m, long long n ){ if ( n == 0) return m; return gcd(n,m%n); }//最大公約数 int main(){ ios::sync_with_stdio(false); cin.tie(0); char cmd; int n,m; ll k; cin >> m >> n >> k; cin >> cmd; VLL x(n); VLL y(m); rep(i,n) cin >> x[i]; rep(i,m) cin >> y[i]; map mpx; map mpy; rep(i,n) mpx[x[i]%k]++; rep(j,m) mpy[y[j]%k]++; if(cmd == '+'){ ll ans = 0; for(auto x: mpx){ ll less = k-x.first; ans += x.second * mpy[less]; } cout << ans << endl; }else{ ll ans = 0; for(auto x: mpx){ // cout << x.first << " ,add "; if(x.first == 0){ // cout << x.second * m << endl; ans += x.second * m; }else{ ll gcdNum = gcd(k,x.first); if(gcdNum == 1){ ll inv = modinv(x.first,k); // cout << x.second * mpy[inv] << " inv " << inv << endl; ans += x.second * mpy[inv]; }else{ ll less = k / gcdNum; ll cnt = 0; while(cnt < k){ ans += x.second * mpy[cnt]; cnt += less; } } } } cout << ans << endl; } // rep(i,12) cout << modinv(i,12) << " "; // cout << endl; // rep(j,m) { // rep(i,n){ // cout << x[i] * y[j] % k << " "; // } // cout << endl; // } return 0; }