N, M, K = map(int, input().split()) op, *B = input().split() A = [int(input())%K for _ in range(N)] b = list(map(int, B)) import numpy as np B = [0]*M for i in range(M): B[i]=b[i]%K if op=='+': cnt=0 for i in range(N): cnt+=max(0,B.count(K-A[i])) else: cnt=(N-(max(0,A.count(0))))*(M-(max(0,B.count(0)))) cnt=N*M-cnt print(cnt)