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