import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int m = sc.nextInt(); int k = sc.nextInt(); boolean isAdd = (sc.next().charAt(0) == '+'); if (isAdd) { HashMap bMods = new HashMap<>(); for (int i = 0; i < m; i++) { int mod = sc.nextInt() % k; bMods.put(mod, bMods.getOrDefault(mod, 0) + 1); } HashMap aMods = new HashMap<>(); for (int i = 0; i < n; i++) { int mod = sc.nextInt() % k; aMods.put(mod, aMods.getOrDefault(mod, 0) + 1); } long ans = 0; for (int x : aMods.keySet()) { int key = (k - x) % k; int value = aMods.get(x); ans += (long)value * bMods.getOrDefault(key, 0); } System.out.println(ans); } else { long bDiv = 0; HashMap bMods = new HashMap<>(); for (int i = 0; i < m; i++) { int x = sc.nextInt(); if (x % k == 0) { bDiv++; } else { int gcd = getGCD(x, k); if (gcd > 1) { bMods.put(gcd, bMods.getOrDefault(gcd, 0) + 1); } } } long aDiv = 0; HashMap aMods = new HashMap<>(); for (int i = 0; i < n; i++) { int x = sc.nextInt(); if (x % k == 0) { aDiv++; } else { int gcd = getGCD(x, k); if (gcd > 1) { aMods.put(gcd, aMods.getOrDefault(gcd, 0) + 1); } } } long ans = bDiv * n + aDiv * (m - bDiv); for (int x : aMods.keySet()) { for (int y : bMods.keySet()) { if (y % (k / x) == 0) { int value = aMods.get(x); ans += (long)value * bMods.get(y); } } } System.out.println(ans); } } static int getGCD(int x, int y) { if (x % y == 0) { return y; } else { return getGCD(y, x % y); } } }