#include #include int main() { uint64_t a, b, c, d; scanf("%llu%llu%llu%llu",&a,&b,&c,&d); printf("%llu\n",a * b % d * c % d); }