#include using namespace std; using ll=long long; int main(){cin.tie(0);ios::sync_with_stdio(false); int N,M,K;cin>>N>>M>>K; string op;cin>>op; ll sa=0,sb=0; for(int i=0;i>B; sb+=B; } sb%=K; for(int i=0;i>A; sa+=A; } sa%=K; if(op=="+"){ cout<<(sa*M+sb*N)%K<<"\n"; }else{ cout<