#include using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); int64_t A, B, C, D; cin >> A >> B >> C >> D; cout << A * B % D * C % D << '\n'; return 0; }