#include using namespace std; struct Initializer { Initializer() { cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(15); } } initializer; int main() { int64_t a, b, c, d; cin >> a >> b >> c >> d; cout << a * b % d * c % d << endl; }