#include int main(){ long long int A, B, C, D; scanf("%lld %lld %lld %lld", &A, &B, &C, &D); printf("%lld\n", A%D*B%D*C%D); return 0; }