#include int main() { size_t a, b, c, d; std::cin >> a >> b >> c >> d; std::cout << (a % d) * (b % d) % d * (c % d) % d << std::endl; }