N, M, K = gets.split.map(&:to_i)
op, *B = gets.chomp.split
B.map!(&:to_i)
A = N.times.map { gets.to_i }

ans = 0
gcd_counter_a = Hash.new(0)
gcd_counter_b = Hash.new(0)
mod_counter = Hash.new(0)

B.each do |b|
  mod_counter[b % K] += 1
  gcd_counter_b[b.gcd(K)] += 1
end

A.each do |a|
  gcd_counter_a[a.gcd(K)] += 1
end

if op == '+'
  A.each do |a|
    if a % K == 0
      ans += mod_counter[0]
    else
      ans += mod_counter[K - a % K]
    end
  end
else
  gcd_counter_a.each do |a, m|
    gcd_counter_b.each do |b, n|
      next if (a * b) % K != 0

      ans += m * n
    end
  end
end

puts ans