// #define _GLIBCXX_DEBUG #include using namespace std; #define int long long #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define rep(i, n) for (int i = 0; i < n; ++i) #define REP(i, n) for (int i = 0; i < n; ++i) #define range(i,a,b) ((a)<=(i) && (i)<(b)) #define debug(x) cout << #x << ' ' << '=' << ' ' << (x) << endl; #define fs first #define sc second #define pb push_back #define eb emplace_back typedef long long ll; typedef pair P; typedef tuple T; typedef vector vec; typedef vector

pvec; typedef vector> vvec; typedef vector> pvvec; typedef priority_queue PQI; typedef priority_queue

PQP; typedef priority_queue,greater> PQIG; typedef priority_queue,greater

> PQPG; const vector dx = {0, -1, 0, 1, 1, 1, -1, -1}; const vector dy = {1, 0, -1, 0, 1, -1, 1, -1}; const int MOD = (1000000007); // const int MOD = (998244353); // const int INF = (1 << 30); const int INF = (1LL << 60); const double EPS = (1 >> 30); template inline bool chmin(T& a, T b) {if (a > b) {a = b; return 1;} return 0;} template inline bool chmax(T& a, T b) {if (a < b) {a = b; return 1;} return 0;} int gcd(int x, int y) { return y ? gcd(y, x%y) : x; } int lcm(int x, int y) { return x/gcd(x, y)*y; } int mod_pow(int x, int y) { int res = 1; while (y > 0) { if (y & 1) { res = res * x % MOD; } x = x * x % MOD; y >>= 1; } return res; } int comb(int n, int k) { k = min(k, n - k); int nnn = 1; for (int i = n - k + 1; i <= n; i++) { nnn *= i; nnn %= MOD; } int kkk = 1; for (int i = 1; i <= k; i++) { kkk *= i; kkk %= MOD; } return (nnn * mod_pow(kkk, MOD - 2)) % MOD; } int to_int(string s) { int n = s.size(); int ans = 0; for (int i = 0; i < n; i++) { ans = ((ans * 10) + (s[i] - '0')) % MOD; } return ans; } int DisitSum(int x){ int ret=0; while(x){ ret++;x/=10;} return ret; } bool is_prime(int n) { for(int i = 2; i*i <= n; i++) { if (n % i == 0) return false; } return n != 1; } int extgcd(int a, int b, int& x, int& y) { // ax+by = gcd(a,b) >> gcd(a,b) int d = a; if(d != 0) { d = extgcd(b, a%b, y, x); y -= (a/b)*x; } else { x = 1, y = 0; } return 0; } signed main() { ios::sync_with_stdio(false); cin.tie(0); cout << fixed << setprecision(15); //--------------------------------------------- int n,m; cin>>n>>m; int k; cin>>k; char x; cin>>x; vec b(m); vec a(n); rep(i,m) cin>>b[i]; rep(i,n) cin>>a[i]; ll cnt=0; if(x=='+'){ rep(i,m) b[i]%=k; rep(i,n) a[i]%=k; sort(all(a));sort(all(b)); rep(i,m){ cnt+=upper_bound(all(a),(k-b[i])%k)-(lower_bound(all(a),(k-b[i])%k)); } cout< mp,mq; rep(i,m) b[i]%=k; rep(i,n) a[i]%=k; rep(i,m) b[i]=gcd(b[i],k),mp[b[i]]++; rep(i,n) a[i]=gcd(a[i],k),mq[a[i]]++; for(auto &x:mp){ for(auto &y:mq){ if((x.fs*y.fs)%k==0){ cnt+=x.sc*y.sc; } } } cout<