#include #define rep(i,a,b) for(int i=a;i=b;i--) #define fore(i,a) for(auto &i:a) #define all(x) (x).begin(),(x).end() //#pragma GCC optimize ("-O3") using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); } typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60; templatebool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; } templatebool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; } //--------------------------------------------------------------------------------------------------- vector enumdiv(int n) { vector S; for (int i = 1; 1LL*i*i <= n; i++) if (n%i == 0) { S.push_back(i); if (i*i != n) S.push_back(n / i); } sort(S.begin(), S.end()); return S; } int gcd(int a, int b) { return a ? gcd(b % a, a) : b; } /*---------------------------------------------------------------------------------------------------             ∧_∧       ∧_∧  (´<_` )  Welcome to My Coding Space!      ( ´_ゝ`) /  ⌒i @hamayanhamayan0     /   \    | |     /   / ̄ ̄ ̄ ̄/  |   __(__ニつ/  _/ .| .|____      \/____/ (u ⊃ ---------------------------------------------------------------------------------------------------*/ int N, M, K; char op; ll B[101010], A[101010]; //--------------------------------------------------------------------------------------------------- void _main() { cin >> N >> M >> K >> op; rep(i, 0, M) cin >> B[i]; rep(i, 0, N) cin >> A[i]; ll ans = 0; if (op == '+') { map cnt; rep(i, 0, M) cnt[B[i] % K]++; rep(i, 0, N) { int b_mo = K - (A[i] % K); b_mo %= K; ans += cnt[b_mo]; } } else { auto ed = enumdiv(K); map cnt, cnt2; rep(i, 0, M) fore(d, ed) if(B[i] % d == 0) cnt[d]++; //rep(i, 0, M) cnt[gcd(K, B[i])]++; //fore(d, ed) fore(d2, ed) if(d % d2 == 0) cnt2[d2] += cnt[d]; rep(i, 0, N) ans += cnt[K / gcd(A[i], K)]; } cout << ans << endl; }