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