#include //using namespace std; typedef unsigned long long ul; typedef signed long long ll; int main(void) { std::cin.tie(0); std::ios::sync_with_stdio(false); std::cout << std::fixed; ll a, b, c, d; std::cin >> a >> b >> c >> d; std::cout << a%d*b%d*c%d << std::endl; return 0; }