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