#include #include #include #include using namespace std; using ll = long long; using pii = pair; using vi = vector; templateusing vv = vector>; #define in(v) v; cin >> v; // #define rep(i,n) for(int i=0;i<(n);++i) #define all(f,c,...) (([&](decltype((c)) cccc) { return (f)(begin(cccc), end(cccc), ## __VA_ARGS__); })(c)) #define _overload3(_1,_2,_3,name,...) name #define _rep(i,n) for(int i=0;i<(n);++i) #define repi(i,a,b) for(int i=(a);i<(b);++i) #define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__) #define rrep(i,n) for(int i=(n);i>=0;--i) const int dx[4]={1,0,-1,0}, dy[4]={0,1,0,-1}; templatebool chmax(T &a,const T &b){if(abool chmin(T &a,const T &b){if(bostream& operator<<(ostream& os,const vector& vec){os<<"{";for(size_t i=0;i&v){for(size_t i=0;iostream& operator<<(ostream& os,const pair& rhs){os<<"("< void debug(const First& first) {cerr< void debug(const First& first, const Rest&... rest) {cerr<> B[i]; rep(i, N) cin >> A[i]; if (op == '+') { vi count(K, 0); rep(i, M) ++count[B[i] % K]; ll ans = 0; rep(i, N) ans += count[(K - A[i] % K) % K]; cout << ans << endl; } else { map count, count2; rep(i, M) ++count[gcd(B[i], K)]; rep(i, N) ++count2[gcd(A[i], K)]; ll ans = 0; for (const auto& [a, e] : count2) { ll tmp = 0; for (int j = 1; j * j <= a; ++j) { if (a % j == 0) { tmp += count[K / (a/j)]; if (a != j * j) tmp += count[K / j]; } } ans += tmp * e; } cout << ans << endl; } return 0; }