#include int main() { int N, M, K; char op; scanf("%d%d%d %c", &N, &M, &K, &op); std::vector A(N), B(M); for (auto& e: B) scanf("%lld", &e); for (auto& e: A) scanf("%lld", &e); int64_t sum{}; for (int i{}; i < N; i++) for (int j{}; j < M; j++) { int64_t ans{}; if (op == '+') ans = A[i] + B[j]; else ans = A[i] * B[j]; sum = (sum + ans) % K; } printf("%lld\n", sum); return 0; }