#include using namespace std; int main(){ long long A,B,C,D; cin >> A >> B >> C >> D; A=(A*B)%D; A=(A*C)%D; cout << A << endl; return 0; }