#include #define trace1(a) cout<<#a<<": "<=(int)(b);--i) #define fore(x,a) for(auto &x:a) #define all(a) (a).begin(),(a).end() #define rall(a) (a).rbegin(),(a).rend() #define isin(i,a,b) ((a) <= (i) && (i) <= (b)) #define uni(a) (a).erase(unique(all(a)),(a).end()) #define dup(x,y) (((x)+(y)-1)/(y)) #define fi first #define se second #define pb push_back #define eb emplace_back #define sz(a) ((long long)(a).size()) #define v(T) vector #define vv(T) v(v(T)) using namespace std; using ll = long long; using vi = vector; using unit= unsigned; using vl = vector; using ull = unsigned long long; using vvi = vector; using pii = pair; using vvl = vector; using pll = pair; using vp = vector; void _main(); int main(){ cin.tie(0); ios::sync_with_stdio(false); _main(); } templatestring join(const v(T)&v){ stringstream s; rep(i,0,sz(v))s<<' '<istream &operator>>(istream&i, v(T)&v){ fore(x,v){ i >> v; } return i; } templateostream &operator<<(ostream&o, const v(T)&v){ o<<"["; fore(x,v)o<ostream &operator<<(ostream&o, const deque&v){ o<<"deq["; fore(x,v)o<ostream &operator<<(ostream&o, const set&v){ o<<"{"; fore(x,v)o<ostream &operator<<(ostream&o, const unordered_set&v){ o<<"{"; fore(x,v)o<ostream &operator<<(ostream&o, const multiset&v){ o<<"{"; fore(x,v)o<ostream &operator<<(ostream&o, const unordered_multiset&v){ o<<"{"; fore(x,v)o<ostream &operator<<(ostream &o, const pair&p){ o<<"("<ostream &operator<<(ostream &o, const map&m){ o<<"{"; fore(x,m)o<"<ostream &operator<<(ostream &o, const unordered_map&m){ o<<"{"; fore(x,m)o<"<void YES(T c){ if(c) cout<<"YES"<void Yes(T c){ if(c) cout<<"Yes"<< endl; else cout<<"No"<void POSS(T c){ if(c) cout<<"POSSIBLE"<void Poss(T c){ if(c) cout<<"Possible"<void chmax(T &a, const T &b){ if(avoid chmin(T &a, const T &b){ if(bT gcd(T a, T b){ return b?gcd(b,a%b):a; } templateT lcm(T a, T b){ return a/gcd(a,b)*b; } const double EPS = 1e-10; const double PI = acos(-1.0); const int INF = 1001002003; const ll LINF= 1001002003004005006LL; const int dx[] = { -1, 0, 1, 0 , -1,-1, 1, 1 }; const int dy[] = { 0, 1, 0,-1 , -1, 1,-1, 1 }; void _main() { int N, M, K; char op; cin >> N >> M >> K >> op; vl a(N), b(M); fore(x, b) cin >> x; fore(x, a) cin >> x; if (op == '+') { ll ans = 0; fore(x, a) ans = (ans + x*M) % K; fore(x, b) ans = (ans + x*N) % K; cout << ans << endl; } else { ll ans = 0; fore(x, a) { ll tmp = 0; fore(y, b) tmp += y; tmp %= K; ans = (ans + ((x * tmp) % K)) % K; } cout << ans << endl; } }