#ifndef LOCAL #include using ll = long long; using uint = unsigned int; using ull = unsigned long long; using ld = long double; using i128 = __int128_t; using u128 = __uint128_t; namespace fastio { static constexpr int BUF_SIZE = 1 << 20; struct Pre { char num[10000][4]; constexpr Pre() : num() { for (int i = 0; i < 10000; i++) { int n = i; for (int j = 3; j >= 0; j--) { num[i][j] = n % 10 | '0'; n /= 10; } } } } constexpr pre; static struct FastOutput { private: static constexpr int TMP_SIZE = 1 << 10; char tmp[TMP_SIZE]; char buf[BUF_SIZE]; size_t buf_pos = 0; template inline char* wt_integer(T x) { char* p = tmp + TMP_SIZE - 1; if (x == 0) { *--p = '0'; } else { bool is_negative = false; if (x < 0) { is_negative = true; x = -x; } while (x >= 10000) { memcpy(p -= 4, pre.num[x % 10000], 4); x /= 10000; } if (x >= 1000) { memcpy(p -= 4, pre.num[x], 4); } else if (x >= 100) { memcpy(p -= 3, pre.num[x] + 1, 3); } else if (x >= 10) { memcpy(p -= 2, pre.num[x] + 2, 2); } else { *--p = pre.num[x][3]; } if (is_negative) *--p = '-'; } return p; } template inline void wt_tuple(const T& t) { if constexpr (N < std::tuple_size::value) { if constexpr (N > 0) wt(' '); const auto x = std::get(t); wt(x); wt_tuple(t); } } public: inline void wt(char c) { buf[buf_pos++] = c; if (buf_pos == BUF_SIZE) flush(); } inline void wt(const char* s) { for (; *s != '\0'; s++) { wt(*s); } } inline void wt(const std::string& s) { for (char c : s) wt(c); } template inline std::enable_if_t> wt(const Tp& x) { std::ostringstream oss; oss << std::fixed << std::setprecision(16) << x; wt(oss.str()); } template inline std::enable_if_t> wt(const Tp& x) { wt(wt_integer(x)); } inline void wt(const __int128_t& x) { wt(wt_integer(x)); } inline void wt(const __uint128_t& x) { wt(wt_integer(x)); } template inline void wt(const std::pair& p) { wt(p.first); wt(' '); wt(p.second); } template inline void wt(const std::tuple& t) { wt_tuple(t); } template inline void wt(const std::array& a) { for (size_t i = 0; i < N; i++) { if (i) wt(' '); wt(a[i]); } } template inline void wt(const std::vector& x) { for (size_t i = 0; i < x.size(); i++) { if (i) wt(' '); wt(x[i]); } } inline void flush() { fwrite(buf, 1, buf_pos, stdout); buf_pos = 0; } ~FastOutput() { flush(); } } fastout; static struct FastInput { private: char buf[BUF_SIZE]; size_t buf_pos = 0; size_t size = 0; char cur = 0; inline char rd_char() { if (buf_pos >= size) { size = fread(buf, 1, BUF_SIZE, stdin); buf_pos = 0; buf[0] = (size == 0 ? -1 : buf[0]); } return cur = buf[buf_pos++]; } template inline void rd_integer(Tp& x) { x = Tp{}; if (skip_blanks()) { int sign = +1; if (cur == '-') { sign = -1; rd_char(); } do { x += x + (x << 3) + (cur & 15); } while (!is_blank(rd_char())); x *= sign; } } inline bool is_blank(char c) { return c <= ' '; } inline bool skip_blanks() { while (is_blank(cur) && cur != -1) { rd_char(); } return cur != -1; } template void rd_tuple(T& t) { if constexpr (N < std::tuple_size::value) { auto& x = std::get(t); rd(x); rd_tuple(t); } } public: inline void rd(char& c) { skip_blanks(); c = cur; rd_char(); } inline void rd(std::string& s) { if (skip_blanks()) { s.clear(); do { s += cur; } while (!is_blank(rd_char())); } } template inline auto rd(T& x) -> std::void_t::value>> { rd_integer(x); } inline auto rd(__int128_t& x) { rd_integer(x); } inline auto rd(__uint128_t& x) { rd_integer(x); } inline void rd(double& x) { std::string s; rd(s); x = std::stod(s); } inline void rd(long double& x) { std::string s; rd(s); x = std::stold(s); } template void rd(std::pair& p) { rd(p.first); rd(p.second); } template void rd(std::tuple& t) { rd_tuple(t); } template void rd(std::array& x) { for (auto& d : x) rd(d); } template void rd(std::vector& x) { for (auto& d : x) rd(d); } } fastin; inline void flush() { fastout.flush(); } void IN() {} template void IN(Head& head, Tails&... tails) { fastin.rd(head); IN(tails...); } template void print(const Last& last) { fastout.wt(last); } template void print(const Head& head, const Tails&... tails) { fastout.wt(head); fastout.wt(' '); print(tails...); } template void println(const Args&... args) { print(args...); fastout.wt('\n'); } } // namespace fastio using fastio::flush; using fastio::IN; using fastio::print; using fastio::println; #define INT(...) \ int __VA_ARGS__; \ IN(__VA_ARGS__) #define LL(...) \ long long __VA_ARGS__; \ IN(__VA_ARGS__) #define STR(...) \ string __VA_ARGS__; \ IN(__VA_ARGS__) #define CHAR(...) \ char __VA_ARGS__; \ IN(__VA_ARGS__) #define DBL(...) \ double __VA_ARGS__; \ IN(__VA_ARGS__) #define VEC(type, name, size) \ vector name(size); \ IN(name) #define VV(type, name, h, w) \ vector> name(h, vector(w)); \ IN(name) #define debug(...) (void(0)) #else #include "algo/debug.h" #endif void solve() { using namespace std; INT(N, M, K); CHAR(o); VEC(ll, B, M); VEC(ll, A, N); if(o == '+') { for(int i = 0; i < N; i++) A[i] %= K; map mp; for(int i = 0; i < M; i++) { B[i] %= K; mp[B[i]]++; } ll ans = 0; for(int i = 0; i < N; i++) { int t = K - A[i]; ans += mp[t == K ? 0 : t]; } println(ans); } else { map a, b; for(int i = 0; i < N; i++) a[gcd(A[i], K)]++; for(int i = 0; i < M; i++) b[gcd(B[i], K)]++; ll ans = 0; for(const auto&[fa, ca] : a) { for(const auto&[fb, cb]: b) { if(fa * fb % K == 0) ans += ca * cb; } } println(ans); } } int main() { int T = 1; // std::cin >> T; while (T--) { solve(); } }