#include #include #define REP(i, n) for (int i = 0; i < n; i++) typedef long long ll; using namespace std; ll mul(ll a, ll b, int K) { ll a_a = a % K; ll b_a = b % K; return (a_a * b_a) % K; } ll plu(ll a, ll b, int K) { ll a_a = a % K; ll b_a = b % K; return (a_a + b_a) % K; } int main() { int N,M,K; cin>>N>>M>>K; string op; cin >> op; vector vc; REP(i, M) { ll l; cin >> l; vc.push_back(l); } ll result = 0; REP(i, N) { ll l; cin >> l; if (op == "+") { REP(j, M) { result += plu(l, vc.at(j), K); } } else if (op == "*") { REP(j, M) { result += mul(l, vc.at(j), K); } } } cout << result % K << endl; return 0; }