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(); char op = sc.next().charAt(0); if (op == '+') { HashMap map = new HashMap<>(); for (int i = 0; i < m; i ++ ){ int mod = sc.nextInt() % k; if (map.containsKey(mod)) { map.put(mod, map.get(mod) + 1); } else { map.put(mod, 1); } } long count = 0; for (int i = 0; i < n; i++) { int mod = sc.nextInt() % k; if (map.containsKey((k - mod) % k)) { count += map.get((k - mod) % k); } } System.out.println(count); } else { HashMap mapB = new HashMap<>(); for (int i = 0; i < m; i ++ ){ int gd = gcd(sc.nextInt(), k); if (mapB.containsKey(gd)) { mapB.put(gd, mapB.get(gd) + 1); } else { mapB.put(gd, 1); } } HashMap mapA = new HashMap<>(); for (int i = 0; i < n; i++) { int gd = gcd(sc.nextInt(), k); if (mapA.containsKey(gd)) { mapA.put(gd, mapA.get(gd) + 1); } else { mapA.put(gd, 1); } } long count = 0; for (Map.Entry entryA : mapA.entrySet()) { for (Map.Entry entryB : mapB.entrySet()) { if ((long)entryA.getKey() * entryB.getKey() % k == 0) { count += (long)entryA.getValue() * entryB.getValue(); } } } System.out.println(count); } } static int gcd(int x, int y) { if (x % y == 0) { return y; } else { return gcd(y, x % y); } } }