#include int main(void) { unsigned long long int a,b,c,d,r; scanf("%llu%llu%llu%llu",&a,&b,&c,&d); r = ((a%d)*(b%d))%d; r*=(c%d); printf("%llu\n",r%d); return 0; }