// http://yukicoder.me/problems/748 #include #include #include int main() { std::cin.tie(0); std::ios::sync_with_stdio(false); std::int64_t a, b, c, d; std::cin >> a >> b >> c >> d; std::cout << ((a % d) * (b % d) % d * (c % d) % d) << std::endl; return EXIT_SUCCESS; }