#include #include using namespace std; int main(){ int N, M, K; cin >> N >> M >> K; char op; cin >> op; vector B(M); for (int i = 0; i < M; i++){ cin >> B[i]; } vector A(N); for (int i = 0; i < N; i++){ cin >> A[i]; } long long sumA = 0; for (int i = 0; i < N; i++){ sumA += A[i]; } sumA %= K; long long sumB = 0; for (int i = 0; i < N; i++){ sumB += B[i]; } sumB %= K; if (op == '+'){ cout << (sumA * M + sumB * N) % K << endl; } if (op == '*'){ cout << sumA * sumB % K << endl; } }