N, M, K = map(int, input().split()) op, *B = input().split() B = list(map(int, B)) A = [int(input()) for _ in range(N)] S = sum(B) res = 0 if op == '+': for i in range(N): res += A[i] * M + S res %= K else: for i in range(N): res += A[i] * S res %= K print(res)