int main(void){ long long a,b,c,d,goukei; scanf("%I64u %I64u %I64u %I64u",&a,&b,&c,&d); printf("%I64u",(a*b*c)%d); return 0; }