#include using namespace std; #define rep(i,n) for(int i=0;i bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;} typedef long long ll; const ll INF = 1e18; const ll MOD = 1e9+7; const ll MAX = 400005; long long fac[MAX], finv[MAX], inv[MAX]; ll modpow(ll a, ll n, ll mod=MOD) { ll res = 1; while (n > 0) { if (n & 1) res = res * a % mod; a = a * a % mod; n >>= 1; } return res; } ll modinv(ll a,ll m=MOD) { ll b=m,u=1,v=0; while(b){ ll t=a/b; a-=t*b; swap(a,b); u-=t*v; swap(u,v); } u%=m; if(u<0) u+=m; return u; } void COMinit(){ fac[0]=fac[1]=1; finv[0]=finv[1]=1; inv[1]=1; for (ll i=2;i> H >> W >> K; string op;cin >> op; ll h[H],w[W]; vector> m(H,vector(W,0)); rep(i,W) cin >> w[i]; rep(i,H) cin >> h[i]; ll wsum = 0; ll wsek = 1; rep(i,W){ wsum += w[i] % K; wsum %= K; } rep(i,W){ wsek *= w[i] % K; wsek %= K; } ll x; if(op == "+"){ x = wsum * H % K; rep(i,H){ x += h[i] * W % K; x %= K; } }else{ x = 0; rep(i,H){ x += wsum * h[i] % K; x %= K; } } cout << x << endl; }