import java.io.BufferedReader; import java.io.InputStreamReader; import java.util.Arrays; import java.util.HashMap; import java.util.Map; public class Main { public static void main(String[] args) throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String[] sa = br.readLine().split(" "); int n = Integer.parseInt(sa[0]); int m = Integer.parseInt(sa[1]); int k = Integer.parseInt(sa[2]); sa = br.readLine().split(" "); String s = sa[0]; long[] b = new long[m]; for (int i = 0; i < b.length; i++) { b[i] = Long.parseLong(sa[i + 1]); } long[] a = new long[n]; for (int i = 0; i < a.length; i++) { a[i] = Long.parseLong(br.readLine()); } br.close(); if ("+".equals(s)) { for (int i = 0; i < a.length; i++) { a[i] %= k; } double[] d = new double[m]; for (int i = 0; i < b.length; i++) { d[i] = b[i] % k; } Arrays.parallelSort(a); Arrays.parallelSort(d); long ans = 0; for (int i = 0; i < a.length; i++) { long v = k - a[i]; int idx1 = Arrays.binarySearch(d, v - 0.5); idx1 = ~idx1; int idx2 = Arrays.binarySearch(d, v + 0.5); idx2 = ~idx2; ans += idx2 - idx1; } System.out.println(ans); } else { Map soinsu = bunkai(k); throw new Exception(); } } static Map bunkai(int n) { Map soinsu = new HashMap<>(); int end = (int) Math.sqrt(n); int d = 2; while (n > 1) { if (n % d == 0) { n /= d; if (soinsu.containsKey(d)) { soinsu.put(d, soinsu.get(d) + 1); } else { soinsu.put(d, 1); } end = (int) Math.sqrt(n); } else { if (d > end) { d = n - 1; } d++; } } return soinsu; } }