#include #define rep(i,n) for (int i = 0; i < (n); ++i) using namespace std; using ll = long long; using P = pair; //N×Mマス計算 int main() { int n,m,k; cin >> n >> m >> k; char op; cin >> op; vector b(m,0); rep(i,m)cin >> b[i]; vector a(n,0); rep(i,n)cin >> a[i]; ll sum = 0; if(op == '+'){ rep(i,n){ rep(j,m){ sum += a[i]+b[j]; // cout << a[i]+b[j] << " "; } // cout << endl; } }else{ rep(i,n){ rep(j,m){ sum += a[i]*b[j]; // cout << a[i]*b[j] << " "; } // cout << endl; } } cout << sum%k << endl; return 0; } /* やっほい!        やほほい!     +    *     ∧∧  . ∧∞∧ * * ヽ(=´ω`)人(´ω`*)ノ  .~( O x.) (   O)~ + 。*   ∪    ∪ */