import java.io.*; import java.util.*; public class Main { public static void main(String[] args) throws Exception { Scanner sc = new Scanner(); int n = sc.nextInt(); int m = sc.nextInt(); int k = sc.nextInt(); if (sc.next().charAt(0) == '+') { HashMap bCounts = new HashMap<>(); for (int i = 0; i < m; i++) { int x = sc.nextInt() % k; bCounts.put(x, bCounts.getOrDefault(x, 0L) + 1); } HashMap aCounts = new HashMap<>(); for (int i = 0; i < n; i++) { int x = sc.nextInt() % k; aCounts.put(x, aCounts.getOrDefault(x, 0L) + 1); } long ans = 0; for (int x : bCounts.keySet()) { if (x == 0) { ans += aCounts.getOrDefault(x, 0L) * bCounts.get(x); } else { ans += aCounts.getOrDefault(k - x, 0L) * bCounts.get(x); } } System.out.println(ans); } else { HashMap bCounts = new HashMap<>(); for (int i = 0; i < m; i++) { int x = getGCD(k, sc.nextInt()); bCounts.put(x, bCounts.getOrDefault(x, 0L) + 1); } HashMap aCounts = new HashMap<>(); for (int i = 0; i < n; i++) { int x = getGCD(k, sc.nextInt()); aCounts.put(x, aCounts.getOrDefault(x, 0L) + 1); } long ans = 0; for (int x : bCounts.keySet()) { for (int y : aCounts.keySet()) { if (y % (k / x) == 0) { ans += bCounts.get(x) * aCounts.get(y); } } } System.out.println(ans); } } static int getGCD(int x, int y) { if (y == 0) { return x; } else { return getGCD(y, x % y); } } } class Scanner { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""); StringBuilder sb = new StringBuilder(); public Scanner() throws Exception { } public int nextInt() throws Exception { return Integer.parseInt(next()); } public long nextLong() throws Exception { return Long.parseLong(next()); } public double nextDouble() throws Exception { return Double.parseDouble(next()); } public String next() throws Exception { while (!st.hasMoreTokens()) { st = new StringTokenizer(br.readLine()); } return st.nextToken(); } }