package main import ( "sort" "bufio" "fmt" "os" "strconv" ) var sc, wr = bufio.NewScanner(os.Stdin), bufio.NewWriter(os.Stdout) func scanString() string { sc.Scan(); return sc.Text() } func scanInt() int { a,_ := strconv.Atoi(scanString()); return a } func scanInt64() int64 { a,_ := strconv.ParseInt(scanString(),10,64); return a } func scanFloat64() float64 { a,_ := strconv.ParseFloat(scanString(),64); return a } func scanInts(n int) []int { res := make([]int, n); for i := 0; i < n; i++ { res[i] = scanInt() }; return res } func abs(a int) int { if a<0 { return -a }; return a } func min(a,b int) int { if ab { return a }; return b } //•*¨*•.¸¸♪Main•*¨*•.¸¸♪( -ω-)ノ ( ・ω・) func main() { sc.Split(bufio.ScanWords) sc.Buffer(make([]byte, 10000), 1000000) n := scanInt() m := scanInt() k := scanInt() op := scanString() ans := 0 b := scanInts(m) a := scanInts(n) if op == "+" { cnt := make(map[int]int, 0) for i := 0; i < m; i++ { b[i] %= k cnt[b[i]]++ } sort.Ints(b) // fmt.Println(b) for i := 0; i < n; i++ { val := (-a[i]%k + k)%k // l := sort.Search(len(b), func(j int) bool { return val <= b[j] }) // r := sort.Search(len(b), func(j int) bool { return val < b[j] }) //ans += r-l ans += cnt[val] // fmt.Println(val) } } else { cnt := make(map[int]int, 0) for i := 0; i < n; i++ { v := gcd(k,a[i]) cnt[k/v]++ } // fmt.Println(cnt) for val, c := range cnt { for i := 0; i < m; i++ { if b[i]%int(val) == 0 { ans += c } } } // fmt.Println(cnt) } fmt.Println(ans) } func gcd(a,b int) int { for b != 0 { a, b = b, a%b }; return a }