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